I often find myself trying to create a categorical variable from a numerical variable + a user-provided set of ranges.
For instance, say that I have a data.frame wi
Use cut()
, already:
df$VCAT2 <- cut(df$V, c(0,9.999,10,20,Inf), labels=F)
Notice the trick I pull to define a very small bin at 10:
10 - 10*.Machine$double.eps
)cut(..., labels)
argument.