df <- data.frame(name=c("r", "h", "s", "l", "e", "m"), value=c(35,20,16,40,23,40)) # get categories df$groups <- cut(df$value, breaks=c(0,21,30,Inf)) # calculate group counts: table(cut(df$value, breaks=c(0,21,30,Inf)))