请问如何将定量数据转为定序数据?
比如年龄18岁以下赋值为1,18-24岁赋值为2,25-29赋值为3,等等?
期待大神回复

# 生成年龄向量
age = c(16, 20, 23, 25, 28, 30, 33, 36)

# 设置分割点,假定分成四个组即: 
# [0,18) [18,25) [25,29) [29,40)
breaks = c(0, 18, 25, 29, 40)

# 验证分组结果
age_group_test = cut(age, breaks, right = FALSE)
print(age_group_test)

# 将年龄向量转换为因子向量
age_group = cut(
  age, breaks, right = FALSE,
  labels = c("1", "2", "3", "4")
)
print(age_group)