Functions for dealing with competition results in long format.


as_longcr(cr_data, repair = TRUE, ...)

# S3 method for longcr
as_tibble(x, ...)



Data of competition results (convertible to tabular).


Whether to repair input.


Additional arguments to be passed to or from methods.


Object to be converted to tibble.


is_longcr() returns TRUE if its argument is appropriate object of class longcr: it should inherit classes longcr, tbl_df (in other words, to be tibble) and have "game", "player", "score" among column names.

as_longcr() returns an object of class longcr.

as_tibble() applied to longcr object drops longcr class.


as_longcr() is S3 method for converting data to longcr. When using default method if repair is TRUE it also tries to fix possible problems (see "Repairing"). If repair is FALSE it converts cr_data to tibble and adds longcr class to it.

When applying as_longcr() to proper (check via is_widecr() is made) widecr object, conversion is made:

  • If there is column game then it is used as game identifier. Else treat every row as separate game data.

  • Every "player"-"score" pair for every game is converted to separate row with adding the appropriate extra columns.

  • Result is arranged by game and identifier of a "player"-"score" pair (extra symbols after "player" and "score" strings in input column names) in increasing order.

  • If repair is TRUE then repair is done.

For appropriate longcr objects as_longcr() returns its input and throws error otherwise.

Long format of competition results

It is assumed that competition consists from multiple games (matches, comparisons, etc.). One game can consist from variable number of players. Inside a game all players are treated equally. In every game every player has some score: the value of arbitrary nature that fully characterizes player's performance in particular game (in most cases it is some numeric value).

longcr inherits from tibble. Data should have at least three columns with the following names:

  • game - game identifier.

  • player - player identifier.

  • score - score of particular player in particular game.

Extra columns are allowed. Note that if object is converted to widecr, they will be dropped. So it is better to store extra information about "game"-"player" pair as list-column "score" which will stay untouched.


Option repair = TRUE (default) in as_longcr() means that its result is going to be repaired with following actions:

  • Detect columns exactly matching "game", "player" or "score". Those are used in the output. If all are detected matched columns are put in the beginning. Other columns are preserved.

  • If not all columns were exactly matched, detect first columns with names containing "game", "player" or "score" (ignoring case). If there are many matching names for one output name then the first one is used. In case of imperfect match, message is given. All other columns are treated as "extra".

  • If some legitimate names aren't detected, respective columns are created and filled with NA_integer_. Also a message is given.

  • If in one game some player listed more than once, the first record is taken.

  • Return the tibble with at least 3 appropriate for longcr columns and column names.

See also


# Repairing example cr_data <- data.frame( playerscoregame_ID = rep(1:5, times = 2), gameId = rep(1:5, each = 2), scoreS = 31:40, scoreSS = 41:50 ) cr_data_long <- as_longcr(cr_data, repair = TRUE)
#> as_longcr: Some matched names are not perfectly matched: #> gameId -> game #> playerscoregame_ID -> player #> scoreS -> score
#> [1] TRUE
#> # A tibble: 10 x 4 #> game player score scoreSS #> <int> <int> <int> <int> #> 1 1 1 31 41 #> 2 1 2 32 42 #> 3 2 3 33 43 #> 4 2 4 34 44 #> 5 3 5 35 45 #> 6 3 1 36 46 #> 7 4 2 37 47 #> 8 4 3 38 48 #> 9 5 4 39 49 #> 10 5 5 40 50