col_flatten: Flatten List Columns into a Wide or Long Form

Description Usage Arguments Value Author(s) References Examples

View source: R/col_flatten.R

Description

Converts list columns into separate columns or into a long form.

Usage

1
2
3
col_flatten(indt, cols, drop = FALSE)

col_flattenLong(indt, cols)

Arguments

indt

The input data.table.

cols

Character vector containing the names of list columns

drop

Logical. Should the list columns be dropped from the original data.table?

Value

A data.table.

Author(s)

Ananda Mahto

References

http://stackoverflow.com/q/34206003/1270695

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
df <- structure(
  list(CAT = structure(1:2, .Label = c("A", "B"), class = "factor"),
       COUNT = list(1:3, 4:5), TREAT = list(c("Treat-a", "Treat-b"), 
       c("Treat-c", "Treat-d", "Treat-e"))), 
       .Names = c("CAT", "COUNT", "TREAT"), 
       row.names = c(NA, -2L), class = "data.frame")
       
col_flatten(df, c("COUNT", "TREAT"), TRUE)


col_flattenLong(df, c("COUNT", "TREAT"))

mrdwab/SOfun documentation built on June 20, 2020, 6:15 p.m.