I need to reorganize my dataframe intro multiple columns (based on the values of column "x" and "y" (ignore column "z"):
dataframe <- data.frame(
x = c("apple", "apple","apple", "orange", "orange","orange","banana", "banana","strawberry"),
y = c("a", "d", "b", "c","e","f","g","h","i"),
z = c(9:1))
> dataframe
x y z
1 apple a 9
2 apple d 8
3 apple b 7
4 orange c 6
5 orange e 5
6 orange f 4
7 banana g 3
8 banana h 2
9 strawberry i 1
So, my new dataframe would be like:
> new_df
apple orange banana strawberry
1 a c g i
2 d e h NA
3 b f NA NA