Hello all,
I would like some help in transforming this data frame:
shots_df <- tibble(
Venue = c("Away", "Home"),
Opponent = c("A", "B"),
Shots = c(6, 16),
ShotsOnTarget = c(1, 8),
Team = c("B", "A"),
match_name = "A_B"
)
shots_df
Where there are stats for a single game with a separate row for each team, to something like this:
shots_transformed_df <- tibble(shots_home = 6,
shots_away = 16,
SOT_home = 1,
SOT_away = 8,
team_home = "A",
team_away = "B",
match_name = "A_B")
shots_transformed_df
Where a single game's stats are all in one row with columns for each stat for the home team and away team separated. I have tried several methods such as paste(collapse = ", ") to get the values in a stat column for each row into one value but then I have trouble trying to place them in the correct new column.
Any help would be appreciated!