Generate a repeating sequence

后端 未结 6 1315
情深已故
情深已故 2021-01-14 01:27

I need to generate a vector of the following format using R:

1:10, 1:10, 11:20, 11:20, ... 121:130, 121:130

Is there an easier way than cre

6条回答
  •  北恋
    北恋 (楼主)
    2021-01-14 01:47

    I think this will do you.

    x <- ((0:12)*10)+1
    y <- x + 9
    
    repeatVectors <- function(x,y){
        rep(seq(x,y),2)
    }
    
    z <- mapply(repeatVectors, x,y)
    z <- as.vector(z)
    

提交回复
热议问题