Purrr function to split rows of tibble into list


#1

is there a function in purrr or tidyr that will split a nxp tibble (y) with list columns to a list (yl) of length n with p elements, where each n is a row from x.

this is with lapply

y <- tibble(a=purrr::rerun(10,tibble(x=purrr::rerun(100,data.frame(xx=rnorm(10))))),b=1:10)

yl <- lapply(1:10,function(x) y%>%slice(x)%>%unlist(.,recursive = FALSE))

yl

yl[[1]]
$a
# A tibble: 100 x 1
                       x
                  <list>
 1 <data.frame [10 x 1]>
 2 <data.frame [10 x 1]>
 3 <data.frame [10 x 1]>
 4 <data.frame [10 x 1]>
 5 <data.frame [10 x 1]>
 6 <data.frame [10 x 1]>
 7 <data.frame [10 x 1]>
 8 <data.frame [10 x 1]>
 9 <data.frame [10 x 1]>
10 <data.frame [10 x 1]>
# ... with 90 more rows

$b
[1] 1

#2

you are looking for purrr::transpose(). If you need the transposed list for a function call, you might also want to have a look at purrr::pmap().