I got England and German soccer data with the following:
dataENG =
Import["https://www.soccerstats.com/results.asp?league=england&\
pmtype=bydate", "Data"];
Drop[Drop[Drop[Cases[dataENG, {_, _, _, _}, Infinity], -4], -1, None],
None, {1, 4, 3}];
Table[If[StringContainsQ[%[[i, 1]], "-"] == True &&
StringContainsQ[%[[i, 2]], "-"] == True , %[[i]], ## &[]], {i, 1,
Length[%]}];
Table[StringSplit[%[[i]], "-"], {i, 1, Length[%]}];
resultsENG =
Transpose[{StringTrim[%[[All, 1, 1]]],
ToExpression[StringTrim[%[[All, 2, 1]]]],
StringTrim[%[[All, 1, 2]]],
ToExpression[StringTrim[%[[All, 2, 2]]]]}];
teamsENG = StringTrim[Union[Transpose[resultsENG][[1]]]];
nENG = Length[resultsENG];
mENG = Length[teamsENG];
dataGER =
Import["https://www.soccerstats.com/results.asp?league=germany&\
pmtype=bydate", "Data"];
Drop[Drop[Drop[Cases[dataGER, {_, _, _, _}, Infinity], -4], -1, None],
None, {1, 4, 3}];
Table[If[StringContainsQ[%[[i, 1]], "-"] == True &&
StringContainsQ[%[[i, 2]], "-"] == True , %[[i]], ## &[]], {i, 1,
Length[%]}];
Table[StringSplit[%[[i]], "-"], {i, 1, Length[%]}];
resultsGER =
Transpose[{StringTrim[%[[All, 1, 1]]],
ToExpression[StringTrim[%[[All, 2, 1]]]],
StringTrim[%[[All, 1, 2]]],
ToExpression[StringTrim[%[[All, 2, 2]]]]}];
teamsGER = StringTrim[Union[Transpose[resultsGER][[1]]]];
nGER = Length[resultsGER];
mGER = Length[teamsGER];
Now, I want to get the vector goalsfor
for England and German Leagues; here the code I wrote:
results1 = {resultsENG, resultsGER};
n1 = {nENG, nGER};
t1 = {teamsENG, teamsGER};
m1 = {mENG, mGER};
goalsfor = ConstantArray[0, Dimensions[Flatten[t1]]];
For[k = 1, k = Length[n1], k++,
Do[Table[
If[results1[[i, All, 1]] == t1[[i, j]],
goalsfor[[j]] =
goalsfor[[j]] + results1[[i, All, 2]], ## &[]], {i, 1,
n1[[k]]} ], {j, 1, m1[[k]]}]];
It sounds good, I should have a vector of numbers equal to the goals of the teams, but if I call goalsfor
I get as a result a constant array of zeros.
Where I am wrong?
For
loop? It should not be difficult to do so using justTable
, and may function better/help you to learn more! $\endgroup$