I have a column with userIds, but I want to change this column into different rows and combine the same values in one row.
Code to produce the data in the image looks like:
userid <- c(415,375,415,415,513,64,375,415,317,375)
rating <- c(4,4,4,5,5,4,3,5,4,5)
title <- c("GoldenEye (1995)","GoldenEye (1995)","Babe (1995)",
"Usual Suspects, The (1995)", "Braveheart (1995)","Braveheart (1995)","Braveheart (1995)",
"Braveheart (1995)","Apollo 13 (1995)","Apollo 13 (1995)")
data <- data.frame(userid,rating,title)
How do I transform the data so the movie titles are columns, with one row per userid, where the ratings are the cells of the data frame?
userid Apollo 13 (1995) Babe (1995) Braveheart (1995) GoldenEye (1995)
1 64 NA NA 4 NA
2 317 4 NA NA NA
3 375 5 NA 3 4
4 415 NA 4 5 4
5 513 NA NA 5 NA
Usual Suspects, The (1995)
1 NA
2 NA
3 NA
4 5
5 NA
>