| .list_of_lists_to_df | R Documentation |
Convert a multilevel list to a nested dataframe
.list_of_lists_to_df(lst, ...)
lst |
a multilevel list |
... |
Named arguments passed on to
|
a dataframe with each sublist nested as a dataframe
iris_list = .df_to_list_of_lists(iris, .fix=FALSE)
iris2 = .list_of_lists_to_df(iris_list, .fix=FALSE)
testthat::expect_equal(datasets::iris, as.data.frame(iris2))
mtcars_nest = datasets::mtcars
dplyr::mutate(name = rownames(.))
tidyr::nest(details = -c(cyl,gear))
mtcars_list = mtcars_nest
mtcars_nest2 = mtcars_list
testthat::expect_equal(
mtcars_nest2$details[[2]],
mtcars_nest$details[[2]]
)
# test unequal length vector column is mapped to list of vectors
# and multiply named nests are treated as rows
testlist = list(
row = list(a=1:5, b="x"),
row = list(a=2:4, b="y"),
row = list(a=3, b="z")
)
testdf = testlist
testthat::expect_equal(testdf$b, c("x", "y", "z"))
testthat::expect_equal(testdf$a[[2]], 2:4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.