x<-sample(30:60,50,TRUE)
y<-cut(x,breaks=c(30,40,50,60))
y
[1] (30,40] (30,40] (50,60] (40,50] (40,50] (40,50] (40,50] (30,40] (30,40]
[10] (50,60] (30,40] (50,60] (30,40] (30,40] (50,60] (50,60] (50,60] (30,40]
[19] (50,60] (30,40] (40,50] (40,50] (30,40] (30,40] (30,40] (40,50] (30,40]
[28] (50,60] (40,50] (40,50] (30,40] (50,60] (40,50] (50,60] (50,60] (30,40]
[37] (50,60] (50,60] (30,40] (50,60] (30,40] (30,40] <NA> (40,50] (30,40]
[46] (40,50] (30,40] (30,40] (30,40] (30,40]
Levels: (30,40] (40,50] (50,60]
table(y)
y
(30,40] (40,50] (50,60]
23 12 14
table(y)[1]
(30,40]
23
问题1:
如果添加了 right=FALSE,则间隔为
(30,40] (40,50] (50,60]
如果添加 right=TRUE,则区间为
[30,40) [40,50) [50,60)
我怎样才能得到诸如 [30,40] (40,50] (50,60]
或'[30,40)[40,50)[50,60]'之类的间隔?
问题2:
table(y)[1]
(30,40]
23
我知道区间 (30,40] 中有 23 个数字,我可以用 . 得到它们
x[x<=40 & x>30]
。
有没有更好的方法来得到结果?