gpt4 book ai didi

r - 按定义的间隔切割

转载 作者:行者123 更新时间:2023-12-03 08:37:49 31 4
gpt4 key购买 nike

R 中是否有某种方法可以按定义的间隔进行切割而不会中断?

例如,如果我想要精确间隔 [1,10] 中的值;默认 cut将此间隔分解为更小的间隔。

最佳答案

要剪切到预定义的间隔,您可以使用 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]

关于r - 按定义的间隔切割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5746544/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com