Ph.D.Student
Ph.D.Student

Reputation: 726

Create a vector from a specific sequence of intervals

I have 20 intervals:

10 intervals from 1 to 250 of size 25:

[1.25] [26.50] [51.75] [76.100] [101.125] [126.150] ... [226.250]

10 intervals from 251 to 1000 of size 75:

[251,325] [326,400] [401,475] [476,550] [551,625] ... [926,1000]

I would like to create a vector composed of the first 5 elements of each interval like:

(1,2,3,5, 26,27,28,29,30, 51,52,53,54,55, 76,77,78,79,80, ...., 
251,252,253,254,255, 326,327,328,329,330, ...)

How create this vector using R?

Upvotes: 1

Views: 284

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 388982

Let's assume you have two interval like :

interval1 <- seq(1.25, 226.250, 25)
interval2 <- seq(251, 1000, 75)

We can create a new interval combining the two and then use mapply to create sequence

new_interval <- c(as.integer(interval1), interval2)
c(mapply(`:`, new_interval, new_interval + 4))
 #[1]   1   2   3   4   5  26  27  28  29  30  51  52  53  54 .....
 #[89] ..... 779 780 851 852 853 854 855 926 927 928 929 930

Upvotes: 1

Related Questions