I have the following example data frame:
library(tibble)
library(tidyverse)
df <- tibble(A = 1, B = 1)
df2 <- tibble(C = 2:4, D = 4:6)
df <- df %>%
nest(B) %>%
mutate(data = map(data, ~df2))
It's a nested 3x2 data frame (df2) in a 1x2 data frame (df). Is there a way to combine purrr::map and dplyr::select to select only column C in the nested data frame? I'm hoping to avoid unnest. The outcome should be:
A data
<dbl> <list>
1 1 <tibble [3 x 1]>
mutate(data = map(data, ~select(df2, "C")))do what you want?df2and notdf. I'd like a solution that usesdatacolumn ofdfonly. I've provided a toy example, but in my actual case, it's easier if I try to select columns from within the nested data.frame.