1. Learn
  2. /
  3. Courses
  4. /
  5. R, Yelp and the Search for Good Indian Food

Exercise

Generating weighted star reviews

Use the combined data set, indian_plus_number, to create weighted star reviews for each user. To do this you will simply multiply the unweighted restaurant review variable stars by the total number of reviews variable total_reviews for each user.

This weighted star variable will allow us to generate weighted star reviews.

Weighted star reviews for each restaurant are created by taking the sum of the weighted_stars variables and dividing them by the sum of the total_reviews variable for each user. This is accomplished using the select(), group_by(), %>% and summarize() functions of the dplyr package.

Instructions

100 XP
  • Create a new column weighted_stars in the indian_plus_number data frame
  • Use select(), group_by(), %>% and summarize() to generate new weighted reviews for each restaurant while also creating columns:

    - Create a variable count that counts the number of reviews for each restaurant with the n() function

    - Calculate the previous average star review using the stars and the count variables

    - Generate new star reviews by dividing the sum of the weighted_stars variable and the sum of the total_reviews variable

    - Finally, compute the difference in the star reviews from by subtracting the new star reviews, new, and the previous average star reviews avg. Assign this variable to diff