list_to_data.frame: Convert a list to a data frame

Description Usage Arguments Value Examples

View source: R/list-utils.R

Description

Converts a list to a data frame, with names in multiple columns.

Usage

1
2
list_to_data.frame(l, name_variables = "names", values_variable = "values",
  stringsAsFactors = getOption("stringsAsFactors"))

Arguments

l

A variable, probably a list.

name_variables

A string. What should the columns formed from the names of l be called?

values_variable

A string. What should the columns formed from the values of l be called?

stringsAsFactors

Should character columns be converted to factors?

Value

data.frame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
(l <- list(
  a = 1,
  2:3,                             # missing names are blank
  c = list(ca = 4:6, 7:10, list(cca = 11:15)),
  d = list()                       # empty elt's silently ignored
))
list_to_data.frame(l)

# Custom column names
list_to_data.frame(l, c("group", "subgroup", "element"), "amount")

listless documentation built on May 2, 2019, 1:08 p.m.