0

How can I repeat the integers 1:20 in a vector 20 times each?

i want something like

s <- 1,1,1,2,2,2,3,3,3 etc.....

(except 20 1's then 20 2's then 20 3's.... you get the idea)

I am trying this

l <- 1:20
S <- for(i in l) rep(i, 20)

an one liner would be awesome, something like this

S <- for (i in 1:20, rep(i, 20))

but I am struggling.

thanks,

Jesse

thelatemail
  • 91,185
  • 12
  • 128
  • 188
c0ba1t
  • 241
  • 2
  • 15

1 Answers1

0

so the answer is definitely

s <- as.numeric(rep(1:20, each = 20))

but what if I wanted to do something like this

y <- 3500, 3750, 4000, 4250.... 6000

would

y <- 3250 + rep(250, 11)

work?

Answer as best I could make it...

a <- rep(1:20, each=8000)
b <- rep(rep(1:20, each=400), 20)
c <- rep(rep(rep(1:20, each=20), 20), 20)
d <- rep(1:20, 8000)

df <- cbind(a,b,c,d)

this should be a unique combination of the integers 1:20 in a 4 by 160000 matrix....

c0ba1t
  • 241
  • 2
  • 15