If I have a vector of ages and a character vector of age categories, is there a way to recode the age vector numerically in ascending order according to my age categories, such that ages in "Age 0 to 20" = 1 and so on. My actual data has 20+ age categories but I've just used 4 in the example. Any help would be really appreciated, thanks.
age <- rnorm(1000, 50, 20)
agecat <- c("Age 0 to 20", "Age 21-40", "Age 41-60", "Age 61 and over")