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:
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:
longcr object use
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() #> as_longcr: Some matched names are not perfectly matched: #> gameSS -> game #> score_game -> score #> # A longcr object: #> # A tibble: 1 x 5 #> game player score PlayerRS extra #> <chr> <dbl> <dbl> <chr> <dbl> #> 1 b 1 10 a -1
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:
widecr object use
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_widecr: Some matched names are not perfectly matched: #> player -> player1 #> score -> score1 #> player1 -> player2 #> PlayerRS -> player3 #> scoreRS -> score3 #> as_widecr: Next columns are not found. Creating with NAs. #> score2 #> # A widecr object: #> # A tibble: 1 x 8 #> game player1 score1 player2 score2 player3 score3 extra #> <chr> <chr> <dbl> <chr> <int> <chr> <dbl> <dbl> #> 1 game b 2 c NA a 1 -1
as_widecr() do actual conversion applied to
longcr objects respectively:
as_longcr(cr_wide) #> # 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 as_widecr(cr_long) #> # 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
comperesexpect data that can be a proper input to
widecrobject, or raw data aligned with long format.
comperesis to have three data frames:
gamefor game identifiers).
playerfor player identifiers).