list_to_data.frame
From listless v0.0-2
by Richard Cotton
Convert a list to a data frame
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
Examples
(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")
Community examples
Looks like there are no examples yet.