Description Usage Arguments Examples
Function to coerce a list (of rows) to a data frame.
1 | list2df(x, col_names, ..., stringsAsFactors = default.stringsAsFactors())
|
x |
A list. Each element corresponds to a row of the upcoming data frame. |
col_names |
Optional. If not provided and if the first list element is a named vector, this vector is used to name the columns of the data frame. |
stringsAsFactors |
Logical. Should the character vector be converted to a factor? |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | my_list <- list(c(23, 21, 41), c(3, 55), 8, c(39, 31, 14))
list2df(my_list)
# Name the columns:
# - Option #1:
list2df(my_list, col_names = letters[1:3])
# - Option #2:
my_list <- list(c(a = 23, b = 21, c = 41), c(d = 3, e = 55), c(f = 8),
c(g = 39, h = 31, i = 14))
list2df(my_list)
# A more tricky case:
my_list <- list(r1 = c(a = 23, 21), r2 = c(c = 41, d = 3, e = 55),
r3 = c(f = 8), r4 = c(g = 39, h = 31, i = 14))
list2df(my_list)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.