fc_sequence_possession: Encode single-match possessions

Description Usage Arguments Value References Examples

View source: R/fc_sequence_possession.R

Description

This function encodes possession sequences for a single match using event data.

Usage

1
fc_sequence_possession(data, event_var, team_var, match = NULL)

Arguments

data

A data frame of event data.

event_var

A character value identifying the variable name that corresponds to the event classification for a given event in data.

team_var

A character value identifying the variable name that corresponds to the team label for a given event in data.

match

A character vector of match id values. Only required to define possession ids and sequences in multi-match data frames. See example below.

Value

A tidy tibble that contains data, and possession_id and possession_seq variables. Variable possession_id maps each event to a possession within a game. Variable possession_seq provides a running count of events within a possession.

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
# load dplyr and purrr for examples
library(dplyr)
library(purrr)

# read event and teams data given in package
events <- system.file("extdata", "events_england.json", package = "scoutr") %>%
  fc_read_events()
teams <- system.file("extdata", "teams.json", package = "scoutr") %>%
  fc_read_teams()

# join events and teams data
x <- left_join(events, teams, by = c("team_id" = "wy_id")) %>%
  select(match_id, event_name, sub_event_name, team_id, name)

fc_sequence_possession(x, event_var = "event_name", team_var = "name")

# multi-match example (fake)
y <- left_join(events, teams, by = c("team_id" = "wy_id")) %>%
  select(match_id, event_name, sub_event_name, team_id, name) %>%
  slice(1:10) %>%
  mutate(match_id = as.character(c(rep(1, 5), rep(2, 5))))

map_df(unique(y$match_id), fc_sequence_possession, data = y,
                           event_var = "event_name", team_var = "name")

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