对于以下示例,如何将大小为0.1的数据合并.
x<-c(0.01,0.34,0.45,0.67,0.89,0.12,0.34,0.45,0.23,0.45,0.34,0.32,0.45,0.21,0.55,0.66,0.99,0.23,.012,0.34)
range frequency
0.1-0.2 a
0.2-0.3 b
0.3-0.4 c
................
................
................
................
Run Code Online (Sandbox Code Playgroud)
问候
Col*_*vel 13
关于@akrun解决方案,我会在文档中发布一些有用的内容?cut,以防万一:
注意
取而代之的
table(cut(x, br)),hist(x, br, plot = FALSE)是更有效和更少的内存饿了.
所以,如果有大量数据,我宁愿选择:
br = seq(0,1,by=0.1)
ranges = paste(head(br,-1), br[-1], sep=" - ")
freq = hist(x, breaks=br, include.lowest=TRUE, plot=FALSE)
data.frame(range = ranges, frequency = freq$counts)
# range frequency
#1 0 - 0.1 2
#2 0.1 - 0.2 1
#3 0.2 - 0.3 3
#4 0.3 - 0.4 5
#5 0.4 - 0.5 4
#6 0.5 - 0.6 1
#7 0.6 - 0.7 2
#8 0.7 - 0.8 0
#10 0.9 - 1 1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17459 次 |
| 最近记录: |