delimitedToLong: delimitedToLong()

Description Usage Arguments Details

Description

Turns delimited data into long form data.

Usage

1
2
3
delimitedToLong(data, longThis, byThis, delimiter = ", ", filter = NULL,
  returnDT = NULL, keepCols = NULL, allCols = FALSE,
  longThisClass = NULL, ...)

Arguments

data

a data.frame or data.table

longThis

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 toThis and byThis columns

longThisClass

optional, the class that you want the column of longThis to be in your final data. All delimited fields are going to be character vectors, as they include character delimiters, so the resulting longThis column is going to be of the class character. You may specify a different class here, ex. factor or numeric.

...

additional arguments to the data.table::merge function if you are either specifying keepCols, or setting allCols to be TRUE. By default, no arguments are given to data.table::merge except for x, y, and by.

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).


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