I am trying to use the cut function to create age intervals. Unfortunately, I receive NAs for values that match the lower end of the first break.
For example:
AGE <- sample(18:50, 100, replace = TRUE)
AGE_GROUPS <- cut(AGE, breaks = c(18, 27, 36, 45))
DF <- data.frame(AGE, AGE_GROUPS)
For all the values where AGE is 18 and above 45, I receive NA in the AGE_GROUPS variable. How can I make sure that the lowest bracket in AGE_GROUPS includes 18 and how can I make sure that the highest bracket includes all values >= 45?
min
andmax
values of the variable, depending on whether I need[
or]
. As an example see thisAGE <- sample(18:50, 100, replace = TRUE); unique(cut(AGE, breaks = c(min(AGE)-1, 19, 27, 36, 45, max(AGE)))); unique(cut(AGE, breaks = c(min(AGE), 19, 27, 36, 45, max(AGE)+1), right = F))
. Only thing you need to check is that you don't have duplicate breaks.