Hi! I have a question: I have made a dataframe as follows:
library(tidyverse) df = tibble(x = c(1,2), y = list(1:3,4:6))
In order to obtain the z column - which is the sum of x and each y^2 - I have done this:
df <- df %>% mutate(z = map2(x,y, ~map2_dbl(.x,.y, ~ (.x + .y^2))))
As you can see, is a bit strange chunk of code, but it works. Now, doing so with rowwise, however, I obtain the following:
df$z2 <- df %>% rowwise() %>% do(z2 = .$x +.$y^2)
My main concern is that I cannot have the columns as I obtained by mapping them. (A z2$z2 column is obtained with the last chunk)
Any suggestion, please?