从r中的向量中找出一列区间值

z9smfwbn  于 2023-01-22  发布在  其他
关注(0)|答案(1)|浏览(130)

假设我有一个数值向量,如X = 1:10000所示,在R中是否有一种方法可以从X中获得10个区间的列表,如Desired_output所示?

Desired_output = list(c(0,1000), c(1001,2000),  c(2001,3000),  c(3001,4000),  c(4001,5000),  
                      c(5001,6000), c(6001,7000), c(7001,8000), c(8001,9000), c(9001,10000))
pzfprimi

pzfprimi1#

使用seq

Map(`c`, c(0, seq(1001, 10000, by = 1000)), seq(1000, 10000, by = 1000))
  • 输出
[[1]]
[1]    0 1000

[[2]]
[1] 1001 2000

[[3]]
[1] 2001 3000

[[4]]
[1] 3001 4000

[[5]]
[1] 4001 5000

[[6]]
[1] 5001 6000

[[7]]
[1] 6001 7000

[[8]]
[1] 7001 8000

[[9]]
[1] 8001 9000

[[10]]
[1]  9001 10000

相关问题