Functions for competition results with games between two players.

to_pairgames(cr_data)

is_pairgames(cr_data)

Arguments

cr_data

Competition results in format ready for as_longcr().

Value

to_pairgames() returns a competition results of pairwise games as widecr object with two players. is_pairgames() returns a boolean value of whether cr_data contains only games between two players.

Details

Pairgames is a term for competition results with games between two players. to_pairgames() is a function that converts competition results into pairwise games: it drops games with one player and for every game with 3 and more players this function transforms it into set of separate games between unordered pairs of players. In other words the result is a set of unordered matchups (as different games) between different players. Important notes:

  • New game identifiers are integers, order of which respects order of games stored in cr_data (based on first occurrence in long format). There is no particular order in subgames of games with 3 and more players.

  • Order in which players are assigned to player1 or player2 column in general shouldn't agree with any order in cr_data.

  • Any column except game, player and score will be dropped after conversion to longcr.

  • NA and NaN in players are allowed. They are treated as different players.

  • to_pairgames() is rather compute-intensive and can take much time for competition results with many games.

Examples

cr_data <- data.frame( game = c(rep(1:5, each = 3), 6), player = c(rep(1:5, times = 3), 1), score = 101:116, extraCol = -(1:16) ) to_pairgames(cr_data)
#> # A widecr object: #> # A tibble: 15 x 5 #> game player1 score1 player2 score2 #> <int> <dbl> <int> <dbl> <int> #> 1 1 1. 101 2. 102 #> 2 2 1. 101 3. 103 #> 3 3 2. 102 3. 103 #> 4 4 4. 104 5. 105 #> 5 5 4. 104 1. 106 #> 6 6 5. 105 1. 106 #> 7 7 2. 107 3. 108 #> 8 8 2. 107 4. 109 #> 9 9 3. 108 4. 109 #> 10 10 5. 110 1. 111 #> 11 11 5. 110 2. 112 #> 12 12 1. 111 2. 112 #> 13 13 3. 113 4. 114 #> 14 14 3. 113 5. 115 #> 15 15 4. 114 5. 115
# Missing values cr_data_na <- data.frame( game = rep(1L, 3), player = c(1, NA, NA), score = 1:3 ) to_pairgames(cr_data_na)
#> # A widecr object: #> # A tibble: 3 x 5 #> game player1 score1 player2 score2 #> <int> <dbl> <int> <dbl> <int> #> 1 1 1. 1 NA 2 #> 2 2 1. 1 NA 3 #> 3 3 NA 2 NA 3
# Checks is_pairgames(cr_data)
#> [1] FALSE
is_pairgames(to_pairgames(cr_data))
#> [1] TRUE