Learn R Programming

listless (version 0.0-2)

list_to_data.frame: Convert a list to a data frame

Description

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

Usage

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

Run this code
(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")

Run the code above in your browser using DataLab