I've read this question here: Convert continuous numeric values to discrete categories defined by intervals
However, I would like to output a numeric (rather than a factor), specifically the numeric value of the lower and/or upper bounds (in separate columns)
In essence, this is right, except that the 'df$start' and 'df$end' are given as factors:
df$start <- cut(df$x,
breaks = c(0,25,75,125,175,225,299),
labels = c(0,25,75,125,175,225),
right = TRUE)
df$end <- cut(df$x,
breaks = c(0,25,75,125,175,225,299),
labels = c(25,75,125,175,225,299),
right = TRUE)
The use of as.numeric()
returns the level of the factor (i.e. values 1-6) rather than the original numbers.