| longcr {comperes} | R Documentation | 
Long format of competition results
Description
Functions for dealing with competition results in long format.
Usage
is_longcr(cr_data)
as_longcr(cr_data, repair = TRUE, ...)
## S3 method for class 'longcr'
as_tibble(x, ...)
Arguments
| cr_data | Data of competition results (convertible to tabular). | 
| repair | Whether to repair input. | 
| ... | Additional arguments to be passed to or from methods. | 
| x | Object to be converted to tibble. | 
Details
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 - gamethen 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 - gameand identifier of a "player"-"score" pair (extra symbols after "player" and "score" strings in input column names) in increasing order.
- If - repairis- TRUEthen repair is done.
For appropriate longcr objects as_longcr() returns its input and
throws error otherwise.
Value
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.
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.
Repairing
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 - longcrcolumns and column names.
See Also
Examples
# 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)
is_longcr(cr_data_long)
as_tibble(cr_data_long)