Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

r - How to find columns with maximum ratings

This problem has to be done in R only not SQL. I have a problem where I am given below dataset.

Data Dictionary

UserID – 4848 customers who provided a rating for each movie - (Row) Movie 1 to Movie 206 – 206 movies for which ratings are provided by 4848 distinct users (Columns)

1) I need to find Which movies have maximum views/ratings?

2) Define the top 5 movies with the least audience

I was able to get the max rating for each movie(column) by below. But after this how do I limit this result with highest rating.. what kind of filter or function can be used.

I used this :

dataset <- read.csv("Amazon - Movies and TV Ratings.csv", row.names = 1)
sapply(dataset,max,na.rm=TRUE)

This gives me one row with max value fr each col (5,5,2,5,3 etc.)

Sample dataset:

                Movie1  Movie2  Movie3  Movie4  Movie5  Movie6


   USer1            5      5      NA     NA     NA     NA
   USer2            NA     NA     2      NA     NA     NA
   USer3            NA     NA     NA      5     NA     NA
   USer4            NA     NA     NA      5     NA     NA
   USer5            NA     NA     NA     NA      5     NA
   USer6            NA     NA     NA     NA      2     NA
   USer7            NA     NA     NA     NA      5     NA
   USer8            NA     NA     NA     NA      2     NA
   USer9            NA     NA     NA     NA      5     NA
   USer10           NA     NA     NA     NA      5     NA

Sample data screenshot: Amazon rating dataset

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For your first question,

data <-cbind(c(1,5,NA,2,3,5,2,3),c(3,NA,4,1,2,1,3,2),c(NA,1,1,3,4,3))
data <- as.data.frame(data)
colnames(data) <- c("Movie1","Movie2","Movie3")
data

apply(data,2,max,na.rm=TRUE)
#Movie1 Movie2 Movie3 
#5      4      4 

For the second question, I believe - you need to specify the criteria on which you want to say a movie is top one. ex : something like do you want to compare the rating with average rating of that movie?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[5] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

56.9k users

...