Hi,
I want to categorize age variable into 4 categories according to 3 division points and percentile width of 25% each.
Here is my attempt and code:
df$age <- structure(c(61, 44, 65, 44, 45, 46, 65, 42, 48, 82, 37, 74, 55,
55, 42, 74, 35, 23, 72, 63, 79, 50, 68, 48, 51, 46, 56, 54, 58,
78, 67, 54, 61, 60, 60, 56, 52, 48, 60, 73, 77, 85, 47, 62, 58,
51, 52, 49, 74, 59, 52, 46, 29, 43, 70, 78, 55, 63, 69, 46, 74,
80, 71, 56, 82, 31, 53, 36, 58, 58, 51, 56, 58, 51, NA, 80, 66,
60, 22, 65, 65, 57, 84, 51, 45, NA, 34, 45, 53, 77, 61, 55, 43,
62, 55, 54, 61, 47, 74, 32, 49, 62, 56, 60, 55, 54, 76, 59, 51,
57, 42, 56, 99, 90, 71, 42, 60, 69, 47, 62, 82, 93), format.spss = "F2.0", display_width = 12L)
quantiles <- quantile(df$age, probs = c(0, 0.25, 0.5, 0.75, 1), na.rm = TRUE)
# Use cut() with custom quantiles to create the categories
labels <- c("Group 1", "Group 2", "Group 3", "Group 4")
I want to know what are the breaks according to age were used? So I want to create another variable showing me this.
How do I do it , please ?
I would like to know which side of break is open and which is closed, something like sometimes is presented by: (15, 23].
So lets say that age of 61 belongs to third group with span of break from 56.5 to 66.5 (if I am not mistaken).
Any help will be much appreciated.