読者です 読者をやめる 読者になる 読者になる

factor(cut()): 連続変数のカテゴリ化

set.seed(314159265)
height <- rnorm(30, 170, 7)
factor(cut(height, breaks = quantile(height, c(0, 0.25, 0.50, 0.75, 1)), include.lowest = TRUE))
 [1] (175,181] (167,172] (167,172] (167,172] (167,172] [158,167] (175,181] (175,181] (167,172]
[10] (172,175] (167,172] (172,175] (175,181] [158,167] [158,167] (175,181] [158,167] (175,181]
[19] (172,175] (172,175] (172,175] (175,181] [158,167] [158,167] [158,167] [158,167] (175,181]
[28] (172,175] (167,172] (172,175]
Levels: [158,167] (167,172] (172,175] (175,181]

たまに使いそう。