我正在尝试找到一种最有效的方法,将数字列表按值拆分为二进制数,然后计算每个连续类别的累计总和。
我似乎无法从图中获得这个值的类别。
> scores
[1] 115 119 119 134 121 128 128 152 97 108 98 130 108 110 111 122 106 142 143 140 141 151 125 126
> table(cut(scores,breaks=10))
(96.9,102] (102,108] (108,113] (113,119] (119,124] (124,130] (130,136] (136,141] (141,147] (147,152]
2 1 4 1 4 5 1 2 2 2
> cumsum(table(cut(scores,breaks=10)))
(96.9,102] (102,108] (108,113] (113,119] (119,124] (124,130] (130,136] (136,141] (141,147] (147,152]
2 3 7 8 12 17 18 20 22 24
> plot(100*cumsum(table(cut(scores,breaks=10)))/length(scores),ylab="percent of scores")
> lines(100*cumsum(table(cut(scores,breaks=10)))/length(scores))
这会产生一个可接受的图,其中包含索引值(2,4,6 ...)。如何获得值96.9,102等...有更好的方法吗?
答案 0 :(得分:1)
您需要设置xaxt = "n"
以强制plot
不显示x轴标签,并使用axis
自行显示它们,同时使用names
{ p>
plot(100*cumsum(table(cut(scores,breaks=10)))/length(scores),ylab="percent of scores", xaxt = "n")
lines(100*cumsum(table(cut(scores,breaks=10)))/length(scores))
axis(1, 1:10, names(table(cut(scores,breaks=10))))