I am working on a rather large dataset in R, containing a continuous numeric variable. In another dataset, I have named intervals, described by min and max values, that I want to apply to the continuous variable in my large dataset.
Below is some example code:
df<-data.frame(x=c(1:6))
groups<-data.frame(cat=c("a","b","c","d"), min=c(1,2,4,6), max=c(2,4,5,8))
I want to make a new column, df$cat, so that the values of df$x are within the min-max boudaries found in the groups data frame.
Ideally, I would like to have groups$min >= df$x > groups$max.
> df
x cat
1 1 a
2 2 b
3 3 b
4 4 c
5 5 d
6 6 d
Is there any easy way of doing this?
5correspond to nothing here, sincedgoes to 6 and 7 whilecgoes to 4? - Psidom