View source: R/utils_name_cleaning.R
clean_homeaway | R Documentation |
This function converts dataframes with "home_" and "away_" prefixed columns to "team_" and "opponent_", and doubles the rows. This makes sure that there's one row for each team (as opposed to one row for each game).
clean_homeaway(dataframe, invert = NULL)
dataframe |
dataframe |
invert |
a character vector of columns that gets inverted when referring to the away team (e.g. home spread = 1 gets converted to away_spread = -1) |
a dataframe with one row per team (twice as long as the input dataframe)
# a small example dataframe
s <- data.frame(
game_id = c("2020_20_TB_GB", "2020_20_BUF_KC", "2020_21_KC_TB"),
game_type = c("CON", "CON", "SB"),
away_team = c("TB", "BUF", "KC"),
away_score = c(31L, 24L, 9L),
home_team = c("GB", "KC", "TB"),
home_score = c(26L, 38L, 31L),
location = c("Home", "Home", "Neutral"),
result = c(-5L, 14L, 22L),
spread_line = c(3, 3, -3)
)
clean_homeaway(s, invert = c("result","spread_line"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.