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 creating 12 vectors and then repeating each of them twice?
Is this what you want?
unlist(lapply(rep(seq(1, 121, by=10), each=2), function(x) seq(x, x+9)))
You can also 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 effective version:
x <- 1:130 dim(x) <- c(10,13) c(rbind(x, x))
Alternatively, you can use a combination of rep and outer , for example:
rep
outer
c(outer(1:10,rep(0:12,each=2),function(x,y)10*y+x))
I think it will make 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)
Method using split -
split
unlist(rep(split(seq_len(130), rep(1:13, each=10)), each=2), use.names=FALSE)
Source: https://habr.com/ru/post/1313666/More articles:Hibernation, SQL and recursive associations - javaC # Document Viewer - .nethttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1313663/how-can-i-programmatically-determine-the-size-of-my-desktop&usg=ALkJrhgxHGHU-yUTEu7I-cWx74pDAKEsogC ++ / CLI Explicitly loading a managed DLL at run time (equivalent to LoadLibrary for unmanaged) - .netSelenium: Why doesn't click () behave like it does in Firefox? - javaClicking a link before loading Javascript (problem) - javascriptStored Procedure Returning UPDATE - sqlUse latin characters in appengine - pythonWhy can a StringTemplate be slow? - javaHow to show download bar on iPhone? - user-interfaceAll Articles