Expand aggregated data Several datasets for the Bradley-Terry Model aggregate the number of wins for each player in a different column. The models we provide are intended to be used in a long format. A single result for each contest. This function expands datasets that have aggregated data into this long format.

expand_aggregated_data(
  d,
  player0,
  player1,
  wins0,
  wins1,
  ties = NULL,
  keep = NULL
)

Arguments

d

a data frame

player0

string with column name of player0

player1

string with column name of player1

wins0

string with column name of the number of wins of player 0

wins1

string with column name of the number of wins of player 1

ties

string with the column of the ties

keep

an array of strings with the name of columns we want to keep in the new data frame (and repeat in every expanded row)

Value

a data frame with the expanded dataset. It will have the columns player1, player0, y, the keep columns, and a rowid column (to make each row unique)

Examples

#Creating a simple data frame with only one row to illustrate how the function works
df1 <- tibble::tribble(~player0, ~player1, ~wins0, ~wins1,~cluster, 'A','B',4, 3, 'c1')
df2 <- expand_aggregated_data(df1,'player0', 'player1', 'wins0', 'wins1', keep=c('cluster'))
print(df2)
#>   player0 player1 y cluster rowid
#> 1       A       B 0      c1     1
#> 2       A       B 0      c1     2
#> 3       A       B 0      c1     3
#> 4       A       B 0      c1     4
#> 5       A       B 1      c1     5
#> 6       A       B 1      c1     6
#> 7       A       B 1      c1     7