Generate a repeating sequence

允我心安 提交于 2019-12-01 06:49:28

Is this what you want?

unlist(lapply(rep(seq(1, 121, by=10), each=2), function(x) seq(x, x+9)))

Also you could do:

rep(1:10, 26) + rep(seq(0,120,10), each=20)

Another way:

x <- matrix(1:130, 10, 13)
c(rbind(x, x))

Possible more efficient version:

x <- 1:130
dim(x) <- c(10,13)
c(rbind(x, x))

Alternatively, you could use a combination of rep and outer, such as:

c(outer(1:10,rep(0:12,each=2),function(x,y)10*y+x))

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)

A method using split is

unlist(rep(split(seq_len(130), rep(1:13, each=10)), each=2), use.names=FALSE)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!