I have two data_frames like so:
df1 <- data_frame(ONE = rep("a", 6),
TWO = letters[2:7])
df2 <- data_frame(id = sample(letters[1:7], 80, replace = TRUE),
dat1 = rnorm(n = 80, 10, 1),
dat2 = rnorm(n = 80, 20, 1))
where the contents of df1 columns ONE and TWO correspond to the id column in df2.
I would like to create a new column in df1 which is a nested column with each row in the column containing a filtered df2 data_frame based on the id values in ONE and TWO.
I was hoping something like this might work:
df1 %>%
mutate(new = map2(ONE, TWO, ~ filter(df2, .x, .y)))
but I get:
Error in mutate_impl(.data, dots) :
Evaluation error: Evaluation error: operations are possible only for numeric, logical or complex types
I have been playing around with nest() and map_df() but am making little headway. What should I try next?