I have a nested dataframe tb
which looks like that:
>tb
# A tibble: 26 x 3
league fdj_data five38_data
<chr> <list> <list>
1 Ch.D1 Danemark <tibble [14 x 1]> <tibble [14 x 1]>
2 Ch.D1 Ecosse <tibble [10 x 1]> <tibble [14 x 1]>
3 Ligue 2 <tibble [20 x 1]> <tibble [19 x 1]>
4 Serie B <tibble [18 x 1]> <tibble [21 x 1]>
5 Liga Segunda <tibble [20 x 1]> <tibble [20 x 1]>
6 Ch.D1 Pays-Bas <tibble [18 x 1]> <tibble [21 x 1]>
7 Ch.D1 Grèce <tibble [12 x 1]> <tibble [16 x 1]>
8 Ch.D1 Suède <tibble [16 x 1]> <tibble [19 x 1]>
9 Ch.D1 Turquie <tibble [18 x 1]> <tibble [21 x 1]>
10 Ch.D1 Russie <tibble [14 x 1]> <tibble [19 x 1]>
# ... with 16 more rows
I also have a function (let's call it func
) which takes 2 character vectors (possibly of different lengths) and output another character vector (same length length as the first arg)
I want to add another column which contains, for each row, func(fdj_data, five38_data)
I've tried
tb %>%
mutate(new_var = func(fdj_data, five38_data))
and
tb %>%
mutate(fdj_data = as.character(fdj_data),
five38_data = as.character(five38_data)) %>%
mutate(new_var = func(fdj_data, five38_data))
But both don't work.
I also tried with purrr::map()
but I wasn't more successful
Have you got any idea ?