list2df | R Documentation |
Converts a list object into a data.frame
list2df(x, name = "name", value = "value", show_NA, warn = TRUE)
x |
A (preferably) named |
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 |
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.
a data.frame
object with columns "name"
and "value"
for the
names of the list
and the values in each
x <- list(a = 1, b = 2:4, c = letters[10:20], "unnamed", "unnamed2")
list2df(x, "col1", "col2", warn = FALSE)
if (getRversion() >= as.package_version('4.0')) {
# contrast with `base::list2DF()` and `base::as.data.frame()`
x <- list(a = 1:3, b = 2:4, c = letters[10:12])
list2df(x, warn = FALSE)
list2DF(x)
as.data.frame(x)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.