Consider the following data frames
df1 <- data.frame(ID = 1:10,
Score = c(73, 53, 8, 100, 39, 62, 78, 89, 61, 18))
df2 <- data.frame(Category = c(10, 20, 30, 40, 50, 60, 70, 80, 90),
Score_min = c(1, 21, 31, 41, 51, 61, 71, 81, 91),
Score_max = c(20, 30, 40, 50, 60, 70, 80, 90, 100))
I want to see which df2$Category each df1$Score is by testing the range between columns df2$Score_min and df2$Score_max
Meaning, for each Score in df1, I want to see where it lies in the range between Score_min and Score_max in df2, and return the Category variable in df2
The output i am hoping to obtain is
final.df <- data.frame(ID = 1:10,
Score = c(73, 53, 8, 100, 39, 62, 78, 89, 61, 18)) %>%
mutate(Category = c(70, 50, 10, 90, 30, 60, 70, 80, 60, 20))
I have tried left_join and lapply with no luck.