How can I transform a variable(0-10) into 3 categories?


The GLEASON variable in the database is from 0 to 10. And I wanted to transform this variable into 3 categories, for example: 0-4: little aggressive, 5-7: intermediate aggressive and 8-10: very aggressive. In R programming. Thank you


Another option is to use the cut function. Using the data.frame created by @Daniel:

dados <- data.frame(GLEASON = sample(0:10, 50, replace = TRUE))
dados$categorias <- cut(dados$GLEASON, c(0,4,7,10),
   include.lowest = T, labels = c("pouco agressivo",
   "agressivo intermedio","muito agressivo"))

The first argument is the numeric vector, the second is the cuts vector, the third is to indicate whether it includes the lowest value, 0, and last are the categories you want.

Scroll to Top