I am trying to get data frame in specific format.
I have 3 attributes user_id, movie_id, movie_ranking.
I want to display best movie_id and ranking for each user based on the maximal ranking.
I guess dplyr library is good for this, but I cannot really get it work.
dplyr, we can group by 'user_id',
arrange the 'movie_ranking' in descending order and
slice the first row.
library(dplyr) df1 %>% group_by(user_id) %>% arrange(desc(movie_ranking)) %>% slice(1L)
A less efficient option would be using
df1 %>% group_by(user_id) %>% slice(which.max(movie_ranking))