我想将一些数据分组为R中的boxplot的几个类别。我获得了这样的组:
cut(60:95, breaks = c(60,64,68,72,76,80,85,90,95))
这是我的输出:
(60,64] (60,64] (60,64] (60,64] (64,68] (64,68] (64,68] (64,68]
(68,72] (68,72] (68,72] (68,72] (72,76] (72,76] (72,76]
(72,76] (76,80] (76,80] (76,80] (76,80] (80,85] (80,85] (80,85] (80,85]
(80,85] (85,90] (85,90] (85,90] (85,90] (85,90] (90,95]
(90,95] (90,95] (90,95] (90,95]
但我真正想要的类别是:
(60,64] (60,64] (60,64] (60,64] (65,68] (65,68] (65,68] (65,68] etc
有谁知道如何获得我想要的输出?
答案 0 :(得分:1)
你的限制(inf和sup)
breaks_lim_inf<-c(60,65,69,73,77,81,86,91)
breaks_lim_sup<-c(64,68,72,76,80,85,90,95)
我建立了休息时间
list_int_unique<-as.factor(paste0("(",breaks_lim_inf,",",breaks_lim_sup,"]"))
list_int_unique
[1] (60,64] (65,68] (69,72] (73,76] (77,80] (81,85] (86,90] (91,95]
Levels: (60,64] (65,68] (69,72] (73,76] (77,80] (81,85] (86,90] (91,95]
我在60到95之间的数字上复制了中断
list<-seq(60,95)
list_int<-list_int_unique[findInterval(list,breaks_lim_inf)]
list_int
您的输出
[1] (60,64] (60,64] (60,64] (60,64] (60,64] (65,68] (65,68] (65,68] (65,68] (69,72] (69,72] (69,72] (69,72] (73,76] (73,76]
[16] (73,76] (73,76] (77,80] (77,80] (77,80] (77,80] (81,85] (81,85] (81,85] (81,85] (81,85] (86,90] (86,90] (86,90] (86,90]
[31] (86,90] (91,95] (91,95] (91,95] (91,95] (91,95]
Levels: (60,64] (65,68] (69,72] (73,76] (77,80] (81,85] (86,90] (91,95]
&#34;(&#34;和&#34;]&#34;的使用是非常规的,我建议阅读此Length
property以更好地理解&#34;(& #34;和&#34;]&#34;