Formats of Competition Results

Evgeni Chasnovski


comperes offers a pipe (%>%) friendly set of tools for storing and managing competition results (hereafter - results). This vignette discusses following topics:

Understanding of competition is quite general: it is a set of games (abstract event) in which players (abstract entity) gain some abstract scores (typically numeric). The most natural example is sport results, however not the only one. For example, product rating can be considered as a competition between products as “players”. Here a “game” is a customer that reviews a set of products by rating them with numerical “score” (stars, points, etc.).

We will need the following packages:



Long format

Results in long format are stored in object of class longcr. It is considered to be a tibble with one row per game-player pair. It should have at least columns with names “game”, “player” and “score”. For example:

To convert cr_long_raw into longcr object use as_longcr():

By default, as_longcr() repairs its input by applying set of heuristics to extract relevant data:

Wide format

Results in wide format are stored in object of class widecr. It is considered to be a tibble with one row per game with fixed amount of players. Data should be organized in pairs of columns “player”-“score”. Identifier of a pair should go after respective keyword and consist only from digits. For example: player1, score1, player2, score2. Order doesn’t matter.

Extra columns are allowed. Column game for game identifier is optional.

Example of correct wide format:

To convert cr_wide_raw into widecr object use as_widecr():

By default, as_widecr() also does repairing of its input:


as_longcr() and as_widecr() do actual conversion applied to widecr and longcr objects respectively:

#> # A longcr object:
#> # A tibble: 6 x 3
#>    game player score
#>   <int>  <dbl> <int>
#> 1     1      1    -1
#> 2     1      2    -4
#> 3     2      1    -2
#> 4     2      3    -5
#> 5     3      2    -3
#> 6     3      3    -6

# Determines number of players in game as
# actual maximum number of players in games
#> # A widecr object:
#> # A tibble: 4 x 7
#>    game player1 score1 player2 score2 player3 score3
#>   <dbl>   <dbl>  <int>   <dbl>  <int>   <dbl>  <int>
#> 1     1       1      1      NA      2      NA      3
#> 2     2       1      4       2      5      NA     NA
#> 3     3       2      6       1      7      NA     NA
#> 4     4       2      8      NA     NA      NA     NA