R - 按定义的间隔切割在R中是否有某种方式可以在没有任何中断的情况下按照定义的间隔进例如,如果我想要精确区间[1,10]中的值; 默认情况下cut,将此间隔分成较小的间隔。
2 回答
汪汪一只猫
TA贡献1898条经验 获得超8个赞
要剪切到预定义的间隔,可以使用breaks
参数指定中断的向量。
定义一些数据:
x <- sample(0:20, 100, replace=TRUE)x
现在在0,10和20处剪切x:
cut(x, breaks=c(0, 10, 20), include.lowest=TRUE) [1] (10,20] [0,10] [0,10] (10,20] (10,20] (10,20] [0,10] (10,20] (10,20] [10] (10,20] [0,10] (10,20] (10,20] (10,20] [0,10] (10,20] [0,10] [0,10] [19] [0,10] (10,20] [0,10] [0,10] [0,10] (10,20] [0,10] (10,20] (10,20] [28] (10,20] (10,20] [0,10] [0,10] [0,10] [0,10] (10,20] [0,10] [0,10] [37] [0,10] [0,10] (10,20] (10,20] (10,20] (10,20] [0,10] (10,20] [0,10] [46] (10,20] [0,10] (10,20] (10,20] [0,10] [0,10] (10,20] (10,20] (10,20] [55] [0,10] [0,10] (10,20] [0,10] [0,10] [0,10] [0,10] (10,20] (10,20] [64] (10,20] [0,10] [0,10] (10,20] (10,20] (10,20] (10,20] (10,20] (10,20] [73] (10,20] [0,10] [0,10] [0,10] (10,20] [0,10] (10,20] [0,10] (10,20] [82] [0,10] [0,10] (10,20] [0,10] [0,10] [0,10] (10,20] (10,20] [0,10] [91] [0,10] [0,10] (10,20] (10,20] [0,10] [0,10] [0,10] [0,10] (10,20][100] (10,20]Levels: [0,10] (10,20]
慕丝7291255
TA贡献1859条经验 获得超6个赞
像这样的东西?每个0.2从0到1中断。
> a <- runif(100)> cut(a, seq(from = 0, to = 1, by = 0.2)) [1] (0,0.2] (0.8,1] (0.8,1] (0.6,0.8] (0.6,0.8] (0,0.2] (0.6,0.8] [8] (0.2,0.4] (0.8,1] (0.4,0.6] (0.8,1] (0.4,0.6] (0.8,1] (0.6,0.8] [15] (0.8,1] (0,0.2] (0.8,1] (0.8,1] (0.6,0.8] (0.6,0.8] (0.2,0.4] [22] (0.4,0.6] (0.6,0.8] (0.2,0.4] (0.6,0.8] (0.6,0.8] (0.6,0.8] (0,0.2] [29] (0,0.2] (0.2,0.4] (0,0.2] (0,0.2] (0,0.2] (0,0.2] (0,0.2] [36] (0.6,0.8] (0.2,0.4] (0.6,0.8] (0.6,0.8] (0.8,1] (0.2,0.4] (0.4,0.6] [43] (0.4,0.6] (0.6,0.8] (0.2,0.4] (0.6,0.8] (0.6,0.8] (0.6,0.8] (0.4,0.6] [50] (0.6,0.8] (0.6,0.8] (0,0.2] (0.2,0.4] (0.8,1] (0.8,1] (0.8,1] [57] (0.6,0.8] (0.2,0.4] (0.2,0.4] (0,0.2] (0.8,1] (0.8,1] (0.2,0.4] [64] (0.8,1] (0.2,0.4] (0.4,0.6] (0.8,1] (0,0.2] (0.4,0.6] (0,0.2] [71] (0.4,0.6] (0.8,1] (0.6,0.8] (0.4,0.6] (0,0.2] (0.2,0.4] (0.4,0.6] [78] (0,0.2] (0.2,0.4] (0.8,1] (0,0.2] (0.4,0.6] (0.8,1] (0,0.2] [85] (0,0.2] (0.2,0.4] (0.2,0.4] (0.4,0.6] (0.8,1] (0.2,0.4] (0,0.2] [92] (0.6,0.8] (0.2,0.4] (0.2,0.4] (0.8,1] (0.2,0.4] (0.4,0.6] (0,0.2] [99] (0,0.2] (0,0.2] Levels: (0,0.2] (0.2,0.4] (0.4,0.6] (0.6,0.8] (0.8,1]
- 2 回答
- 0 关注
- 1020 浏览
添加回答
举报
0/150
提交
取消