longToDelimited: longToDelimited()

Description Usage Arguments Details Examples

Description

Turns long data into delimited data.

Usage

1
2
longToDelimited(data, delimitThis, byThis, delimiter = ", ", filter = NULL,
  returnDT = NULL, keepCols = NULL, allCols = FALSE)

Arguments

data

a data.frame or data.table

delimitThis

the column that you want to become a delimited field

byThis

the Id column which seperates different delimited sections

delimiter

which delimiter do you want to use? Default is ", "

filter

a data.table i expression (roughly equivalent to dplyr's filter function) to filter the data before creating delimited fields

returnDT

NULL by default, can set to TRUE or FALSE to explicitly return a data.table. By default, a data.table is returned if table is a data.table, and a data.frame is returned if table is a data.frame.

keepCols

a vector of column names from data to keep in the final table. Keep in mind that only the first column corresponding with each byThis will be kept. Using keepCols is really only useful when the columns you are interested in have identical rows for each unique value of byThis.

allCols

FALSE by default, if TRUE, sets keepCols to every column except for the delimitThis and byThis columns

Details

Ex., imagine you have a table with 2 columns, the first is an Id column with "A" repeated 3 times, the second column has rows X then Y then Z. This function would turn this table from having three rows into having one row where X, Y, Z are delimited by some delimiter (the default is ", " like the above example).

Examples

1
\code{delimited <- longToDelimited(myData, "soccerPlayers", "team")}

jakesherman/jakemisc documentation built on May 18, 2019, 9:08 a.m.