-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubroutines.R
49 lines (35 loc) · 1.26 KB
/
subroutines.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# ------------------------------------------------------------------------------
# Subroutines need to carry out the main execution routine
#
# Author: Mario Loaiciga
# ------------------------------------------------------------------------------
library(dplyr)
compute_mean_ratings <- function(ratings_df, debug=FALSE) {
# Compute the mean of columns in the ratings dataframe
mean_ratings_df <- group_by(ratings_df, movieId) %>% summarize(
meanRating = mean(rating, na.rm = TRUE)) # group by movie and average ratings
if(debug) {
print("DEBUG - df of mean ratings:")
print(head(mean_ratings_df))
}
return(mean_ratings_df)
}
sort_mean_ratings <-function(mean_ratings_df, debug=FALSE) {
# Sort the movies in descending order accordig to their mean rating
mean_ratings_df <- arrange(mean_ratings_df, desc(meanRating))
if(debug) {
print("DEBUG - df sorted by mean rating:")
print(head(mean_ratings_df))
}
return(mean_ratings_df)
}
sort_movies_ids <-function(ratings_df, debug=FALSE) {
# Sort the movies in descending order accordig to their ID
ratings_df <- arrange(ratings_df, desc(movieId))
if(debug) {
print("DEBUG - df sorted by id:")
print(head(ratings_df))
}
return(ratings_df)
}