knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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:
library(comperes) library(tibble)
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:
cr_long_raw <- tibble( game = c(1, 1, 1, 2, 2, 3, 3, 4), player = c(1, NA, NA, 1, 2, 2, 1, 2), score = 1:8 )
To convert cr_long_raw
into longcr
object use as_longcr()
:
cr_long <- as_longcr(cr_long_raw) cr_long
By default, as_longcr()
repairs its input by applying set of heuristics to extract relevant data:
tibble( PlayerRS = "a", gameSS = "b", extra = -1, score_game = 10, player = 1 ) %>% as_longcr()
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:
cr_wide_raw <- tibble( player1 = c(1, 1, 2), score1 = -(1:3), player2 = c(2, 3, 3), score2 = -(4:6) )
To convert cr_wide_raw
into widecr
object use as_widecr()
:
cr_wide <- cr_wide_raw %>% as_widecr() cr_wide
By default, as_widecr()
also does repairing of its input:
tibble( score = 2, PlayerRS = "a", scoreRS = 1, player = "b", player1 = "c", extra = -1, game = "game" ) %>% as_widecr()
as_longcr()
and as_widecr()
do actual conversion applied to widecr
and longcr
objects respectively:
as_longcr(cr_wide) # Determines number of players in game as # actual maximum number of players in games as_widecr(cr_long)
comperes
expect data that can be a proper input to as_longcr()
, i.e. longcr
object, widecr
object, or raw data aligned with long format.The preferred way to do data analysis with comperes
is to have three data frames:
game
for game identifiers).player
for player identifiers).This way one can operate with games between variable number of players with minimum storage overhead.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.