I have two data frames:
set.seed(343)
testDF <- data.frame(Score = sample(50, size=50, replace=TRUE), number = rep(letters[1:25],2), Rev = rep(0,50))
sourceDF <- data.frame(min = c(1,10,20,30,40), max = c(9, 19, 29, 39, 50), rev = 1:5)
For each line of testDF, where testDF $ score is between sourceDF $ min and sourceDF $ max of sourceDF, replace the value of testDF $ Rev with the corresponding sourceDF $ rev.
I have work with two for loops and an if condition, but this is ... slow (my dataset has about 1 million rows). I tried using findInterval without success.
Is there a better / more efficient way to do this?
source
share