Description Usage Arguments Value Examples
View source: R/soccerFlipDirection.R
Normalises direction of attack in both halves of both teams by flipping x,y-coordinates horizontally in either the first or second half; i.e. teams attack in the same direction all game despite changing sides at half-time.
1 2 3 4 5 6 7 8 9 10 11 | soccerFlipDirection(
df,
lengthPitch = 105,
widthPitch = 68,
teamToFlip = NULL,
periodToFlip = 1:2,
team = "team",
period = "period",
x = "x",
y = "y"
)
|
df |
dataframe containing unnormalised x,y-coordinates |
lengthPitch, widthPitch |
length, width of pitch in metres |
teamToFlip |
character, name of team to flip. If |
periodToFlip |
integer, period(s) to flip |
team |
character, name of variables containing x,y-coordinates |
period |
character, name of variable containing period labels |
x, y |
character, name of variables containing x,y-coordinates |
a dataframe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | library(dplyr)
# flip x,y-coords of France in both halves of statsbomb data
data(statsbomb)
statsbomb %>%
soccerFlipDirection(team = "team.name", x = "location.x", y = "location.y",
teamToFlip = "France")
# flip x,y-coords in 2nd half of Tromso, based on a dummy period variable
data(tromso)
tromso %>%
mutate(period = if_else(t > as.POSIXct("2013-11-07 21:14:00 GMT"), 1, 2)) %>%
soccerFlipDirection(periodToFlip = 2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.