I have the following data which looks like that:
tibble(
name = paste0("segment",1),
data = list(tibble(segment1 = 1:5, check = 99))
)
# A tibble: 1 x 2
name data
<chr> <list>
1 segment1 <tibble [5 x 2]>
I want to map over the nested data and want to use a variable (name) in dplyr. If in column name segment1 is 2 than 66 otherwise use values from column segment1
tibble(
name = paste0("segment",1),
data = list(tibble(segment1 = 1:5, check = 99))
) %>%
mutate(testing = map2(.x = name, .y = data,
~ .y %>%
mutate(testing = ifelse((!!.x) == 2, 66, (!!.x)))))
The unnested testing tibble should look like:
# A tibble: 5 x 3
segment1 check testing
<int> <dbl> <dbl>
1 1 99 1
2 2 99 66
3 3 99 3
4 4 99 4
5 5 99 5
But I always get the error that .x couldn't be found.