UPDATED
Patterns are the key to this one.
Just pick off the games themselves from the results.
games = Partition[Flatten@results[[All, 2]], 4]
(* {{team1, team2, 4, 0}, {team3, team4, 2, 1}, {team2, team3, 2, 4},
{team4, team1, 1, 3}, {team1, team3, 0, 1}, {team4, team2, 2, 2}} *)
Define this pattern and the replacement right hand side. The th
is "team home" ,etc. It parses out the home and away teams and sets up the data. I didn't know what your home
meant, so I just generate records with 5 fields.
patt = {th_, ta_, ths_, tas_} :> {{th, 1, ths, tas, 0, 0, 0}, {ta, 0, 0, 0, 1, tas, ths}}
Run it over the games
res = Cases[games, patt]
(* {{{team1, 1, 4, 0, 0, 0, 0}, {team2, 0, 0, 0, 1, 0, 4}},
{{team3, 1, 2, 1, 0, 0, 0}, {team4, 0, 0, 0, 1, 1, 2}},
{{team2, 1, 2, 4, 0, 0, 0}, {team3, 0, 0, 0, 1, 4, 2}},
{{team4, 1, 1, 3, 0, 0, 0}, {team1, 0, 0, 0, 1, 3, 1}},
{{team1, 1, 0, 1, 0, 0, 0}, {team3, 0, 0, 0, 1, 1, 0}},
{{team4, 1, 2, 2, 0, 0, 0}, {team2, 0, 0, 0, 1, 2, 2}}} *)
Do a GatherBy
on team names after flattening things out.
res2 = GatherBy[Partition[Flatten@res, 7], First];
(* {{{team1, 1, 4, 0, 0, 0, 0}, {team1, 0, 0, 0, 1, 3, 1}, {team1, 1, 0, 1, 0, 0, 0}},
{{team2, 0, 0, 0, 1, 0, 4}, {team2, 1, 2, 4, 0, 0, 0}, {team2, 0, 0, 0, 1, 2, 2}},
{{team3, 1, 2, 1, 0, 0, 0}, {team3, 0, 0, 0, 1, 4, 2}, {team3, 0, 0, 0, 1, 1, 0}},
{{team4, 0, 0, 0, 1, 1, 2}, {team4, 1, 1, 3, 0, 0, 0}, {team4, 1, 2, 2, 0, 0, 0}}} *)
Sum up the values for each team, and label by team.
res3 =Flatten@{First@First@#, Rest[Total[#]]} & /@ res2
(* {{team1, 2, 4, 1, 1, 3, 1},
{team2, 1, 2, 4, 2, 2, 6},
{team3, 1, 2, 1, 2, 5, 2},
{team4, 2, 3, 5, 1, 1, 2}} *)
Join[{{team, home, hgscored, hgconceded, away, agscored, agconceded}}, res3] // TableForm
$$
\left(
\begin{array}{ccccccc}
\text{team} & \text{home} & \text{hgscored} & \text{hgconceded} & \text{away} & \text{agscored} & \text{agconceded} \\
\text{team1} & 2 & 4 & 1 & 1 & 3 & 1 \\
\text{team2} & 1 & 2 & 4 & 2 & 2 & 6 \\
\text{team3} & 1 & 2 & 1 & 2 & 5 & 2 \\
\text{team4} & 2 & 3 & 5 & 1 & 1 & 2 \\
\end{array}
\right)
$$
Not sure the details on your analysis of the data, but this gets it in a form you can work with.