I have following data frame:
id <- c(1,1,2,3,3,4)
fruits <- c(banana, apple, pear, mango, banana, grape)
id_fruit <- data_frame(id, fruits)
As you can see some id´s have more than one fruit. Therefore I want to create two new columns based on the fruit variable. For example "fruit1" and "fruit2".
Then the dataset would be:
id <- c(1,2,3,4)
fruit1 <- c(banana,pear,mango,grape)
fruit2 <- c(apple,NA, banana, NA)
How can I do this with tidyverse?