I have the following two tables:
Table_1
ID Interval
1 10
1 11
2 11
and
Table_2
ID Interval Rating
1 10 0.5
1 10 0.3
1 11 0.1
2 11 0.1
2 11 0.2
The output table should look like this:
ID Interval Mean Ratings
1 10 0.4
1 11 0.1
2 11 0.15
My goal is to join both tables based on the two conditions/columns ID and interval. Given that I have several ratings for the same ID and interval, I want to compute the mean of the ratings. Whereas the IDs are unique (~9500), the interval repeats for different IDs (as seen in the table above). My current approach is the join function with 2 by arguments. How can I create a final table in which Table_1 and Table_2 are joined based on the condition ID and interval, and receive the average rating in the result column?
left_join(Table_1, Table_2, by = c("ID" = "ID", "Interval" = "Interval"))