factor_teams: Coerce teamnames into factors

Description Usage Arguments Examples

View source: R/factor_teams.R

Description

Modelling team strengths often requires separate parameters for offence and defence. These helper functions provide a quick way to turn a factor of team names into a factor of offence or defence levels

Usage

1
factor_teams(data, columns)

Arguments

data

A data frame containing match data.

columns

A charater vector containing the names of columns containing team names.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# For a given dataframe of matches...
games <- data.frame(
  home = c("Arsenal", "Barcelona", "Arsenal"),
  away = c("Chelsea", "Roma",      "Barcelona"),
  result = c("H", "A", "H"),
  stringsAsFactors = FALSE
)

# Convert the teams to factors
games <- factor_teams(games, c("home", "away"))
levels(games$home)
#> c("Arsenal", "Barcelona", "Chelsea", "Roma")

Torvaney/regista documentation built on June 7, 2021, 12:21 a.m.