I am trying to categorize a numeric variable (age) into groups defined by intervals so it will not be continuous. I have this code:
data$agegrp(data$age >= 40 & data$age <= 49) <- 3
data$agegrp(data$age >= 30 & data$age <= 39) <- 2
data$agegrp(data$age >= 20 & data$age <= 29) <- 1
the above code is not working under survival package. It’s giving me:
invalid function in complex assignment
Can you point me where the error is? data is the dataframe I am using.
I would use
findInterval()here:First, make up some sample data
Use
findInterval()to categorize your “ages” vector.Alternatively, as recommended in the comments,
cut()is also useful here: