list2df: List to data.frame

Description Usage Arguments Details Value Examples

View source: R/dataframes.R

Description

Converts a list object into a data.frame

Usage

1
list2df(x, name = "name", value = "value", show_NA, warn = TRUE)

Arguments

x

A (preferably) named list with any number of values

name, value

Names of the new key and value columns, respectively

show_NA

Ignored; if set will trigger a warning

warn

Logical; if TRUE will show a warning when

Details

Unlike base::list2DF(), list2df() tries to format the data.frame by using the names of the list as values rather than variables. This creates a longer form list that may be more tidy.

Value

a data.frame object with columns "name" and "value" for the names of the list and the values in each

Examples

1
2
3
4
5
6
7
x <- list(a = 1, b = 2:4, c = letters[10:20], "unnamed", "unnamed2")
list2df(x, "col1", "col2", warn = FALSE)

# contrast with `base::list2DF()`
if (packageVersion("base") >= as.package_version('4.0')) {
  list2DF(x)
}

mark documentation built on July 16, 2021, 9:07 a.m.