fc_velocity_event: Compute velocity of events

Description Usage Arguments Value References Examples

View source: R/fc_velocity_event.R

Description

This function computes velocities for each event in the event location data.

Usage

1
fc_velocity_event(data, start_loc, end_loc, direction = "all")

Arguments

data

A data frame with event location data. data at minimum must contain variables named match_id, match_period, possession_id, and event_sec.

start_loc

A character vector identifying the x and y coordinates for the start of an event in data.

end_loc

A character vector identifying the x and y coordinates for the end of an event in data.

direction

A character vector specifying the direction of velocity to compute. It can be a subset of c("east", "west", "north", "south", "east_west", "north_south"). The default value computes all six velocities and the total speed. Setting direction = NULL will only compute the total speed.

Value

A tidy tibble with mutated columns giving the velocities specified by direction.

References

Pappalardo, L., Cintia, P., Rossi, A. et al. A public data set of spatio-temporal match events in soccer competitions. Sci Data 6, 236 (2019). https://doi.org/10.1038/s41597-019-0247-7

All public Wyscout data is available at https://figshare.com/collections/Soccer_match_event_dataset/4415000/2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# load dplyr for examples
library(dplyr)

# read event data given in package
file_path <- system.file("extdata", "events_england.json", package = "scoutr")

events <- fc_read_events(file_path) %>%
  fc_locations_transform(x = c("start_x", "end_x"), y = c("start_y", "end_y")) %>%
  fc_sequence_possession(event_var = "event_name", team_var = "team_id") %>%
  select(match_id, match_period, possession_id, event_sec:end_y)

# compute all velocities and speed
events %>%
  fc_velocity_event(start_loc = c("start_x", "start_y"), end_loc = c("end_x", "end_y"),
                    direction = "all")

# compute speed
events %>%
  fc_velocity_event(start_loc = c("start_x", "start_y"), end_loc = c("end_x", "end_y"),
                    direction = NULL)

# compute a subset of velocities
events %>%
  fc_velocity_event(start_loc = c("start_x", "start_y"), end_loc = c("end_x", "end_y"),
                    direction = c("east_west", "north_south"))

shawnsanto/scoutr documentation built on Feb. 27, 2021, 1:02 p.m.