更新时间:2023-12-01 11:36:04
@joran已经提到了 cut
函数.所以这是代码:
@joran already mentioned cut
function. So here is the code:
# Fake data
brfss2013 <- data.frame(X_bmi5 = rnorm(30, 28, 5))
labels <- c('underweight', 'normal', 'overweight',
'class 1 obesity', 'class 2 obesity', 'class 3 obesity')
breaks <- c(0, 18.5, 24.9, 29.9, 34.9, 39.9, 1000)
brfss2013 <- brfss2013 %>%
mutate(brfss2013 = cut(X_bmi5, breaks = breaks,
labels = labels, include.lowest = TRUE))