I have read this question, and I cannot make sense of it in my case, where I have ggplots in my tibble.
Say I have:
library(tidyverse)
f <- function(n) {
p <- tibble(x = rnorm(30, n)) %>%
ggplot(aes(x = x)) + geom_density()
return(list(n = n, p = p))
}
m <- map(seq(10), f)
I would like to turn m into a tibble, with ten rows and two columns, named n and p.
I also would like my code to work with any number of columns, any type of column, if possible.
as_tibble(transpose(m))
gives me
# A tibble: 10 x 2
n p
<list> <list>
1 <int [1]> <gg>
2 <int [1]> <gg>
3 <int [1]> <gg>
...
i.e. each cell is a list, with one element. I would like to transform each list to a scalar.
What I have tried:
- I have used
map_intfor the columnn, but what to do with columnp? unnestalso work for columnn, but not withp.- Same with
unliston the columnp(even withrecursive = FALSE).