Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

find a list of interval values from a vector in r

Say I have a numeric vector as in X = 1:10000. Is there currently a way in R to obtain a list of 10 intervals from X as shown in my 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))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use seq

Map(`c`, c(0, seq(1001, 10000, by = 1000)), seq(1000, 10000, by = 1000))

-output

[[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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading