将极值箱分组为一个“> x”箱

时间:2013-06-17 05:05:42

标签: r histogram

是否已存在函数/方法来确定数据的频率大于某个值?类似于Excel频率分布,我想将极值组合到最后一个箱中(例如,如图像中的> 120)。我一直在手动执行此操作,首先使用hist函数,然后将大于给定值的中断计数求和。

Histogram with bins, 0, 10, 20, ..., 120, >120

1 个答案:

答案 0 :(得分:7)

这是一个选项:

d <- rlnorm(1000, 3)
d.cut <- cut(d, c(seq(0, 120, 10), Inf))
hist(as.numeric(d.cut), breaks=0:13, xaxt='n', xlab='', 
     col=1, border=0, main='', cex.axis=0.8, las=1)
axis(1, at=0:13, labels=c(seq(0, 120, 10), '>120'), cex.axis=0.8)
box()

enter image description here