I need to do the following in R: I have a number (N), for example N <- 7
and I have a length (size), for example size <- 3
And for example if N==7 and size==3, I need to get an output a vector same as:
v <- c(1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3)
you see in v, each number from 1 to size is repeated N times. Is there any way to do this in R without using a for loop?
你可以试试
rep(seq(size), each=N)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.