Consider the following dataframe:
lookup <-
data.frame(
level = 1:5,
points_needed = c(150, 250, 420, 580, 620)
)
lookup
level points_needed
1 1 150
2 2 250
3 3 420
4 4 580
5 5 620
Now consider the following observations:
data <-
data.frame(
person_name = c("Bob", "Bob", "Bob", "Jim", "Jim"),
match = c(1, 2, 3, 1, 2),
total_points = c(100, 300, 430, 200, 600)
)
data
person_name match total_points
1 Bob 1 100
2 Bob 2 300
3 Bob 3 430
4 Jim 1 200
5 Jim 2 600
I would like to create new columns in data. This column would indicate the level of the person_name
- this changes based on the total_points
in relation to the lookup
table. Desired result:
data
person_name match total_points level
1 Bob 1 100 0
2 Bob 2 300 2
3 Bob 3 430 3
4 Jim 1 200 1
5 Jim 2 600 5
I can't use a join here since there's nothing to join on. Any suggestions?