Learn R Programming

soccermatics (version 0.9.5)

soccerFlipDirection: Flips x,y-coordinates horizontally in one half to account for changing sides at half-time

Description

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.

Usage

soccerFlipDirection(
  df,
  lengthPitch = 105,
  widthPitch = 68,
  teamToFlip = NULL,
  periodToFlip = 1:2,
  team = "team",
  period = "period",
  x = "x",
  y = "y"
)

Arguments

df

dataframe containing unnormalised x,y-coordinates

lengthPitch, widthPitch

length, width of pitch in metres

teamToFlip

character, name of team to flip. If NULL, all x,y-coordinates in df will be flipped

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

Value

a dataframe

Examples

Run this code
# NOT RUN {
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)
  
# }

Run the code above in your browser using DataLab