Replacing numbers within a range with a factor [duplicate]
Use cut to do this in one step: dfc <- cut(df$x, breaks=c(0, 15, 45, 56, Inf)) str(dfc) Factor w/ 4 levels “(0,15]”,”(15,45]”,..: 3 4 3 2 2 4 2 2 4 4 … Once you are satisfied that the breaks are correctly specified, you can then also use the labels argument to relabel the levels: … Read more