Home > database >  Sequence of sequences with increasing start in R
Sequence of sequences with increasing start in R

Time:01-18

I am searching for a simple and elegant (basic R functions, no for cyclus) mechanism as function(start:stop) which would create, for example function(2:5) the following vector sequence:

c(2:5, 3:5, 4:5, 5:5)

2,3,4,5,3,4,5,4,5,5

I have tried to put this into the function seq(). Sadly, function seq() does not allow for vector in the argument: from=....

Do you know some solution?

Thank you very much

CodePudding user response:

We may use rep

x1 <- 2:5   rep(0:3, each = 4)
x1[x1 <6]
  •  Tags:  
  • r
  • Related