I want to map two data frames based on conditional expressions to more than one column, but I cannot figure out how to do this. Therefore, if there are my data sets:
df1 <- data.frame(lower=c(0,5,10,15,20), upper=c(4,9,14,19,24), x=c(12,45,67,89,10))
df2 <- data.frame(age=c(12, 14, 5, 2, 9, 19, 22, 18, 23))
I want to match the age of df2, which falls into the range between the lower and upper in df1 in order to add an additional column in df2 containing the value of x in df1, where the age lies between the upper and lower. those. I want df2 to look like
age x
12 67
14 67
5 45
....etc.
How can I achieve such a fit?
source
share