Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

About a year ago I was working on an analysis that required me to take about 20 continuous variables and turn each into a factor based on some banding rule. The rules were complicated enough that using cut() was painful.

cut() works great when the banding you want to do is simple. For example,

vals <- c(22, 69, 89, 56, 33, 57, 10, 38, 50, 25)
cut(
vals,
breaks = c(0, 50, 65, 100),
labels = c('Low', 'Med', 'High')
)

##  [1] Low  High High Med  Low  Med  Low  Low  Low  Low
## Levels: Low Med High