-2

I need to create a pattern like this with the rep() and seq() commands.
It should look like this:

[1] 0.0 0.0 0.0 0.8 0.8 0.8 1.6 1.6 1.6 2.4 2.4 2.4 3.2 3.2 3.2 4.0 4.0 4.0 4.8 [20] 4.8 4.8

Do you have any idea how to do so?

Domewitz
  • 21
  • 2
  • This is already answered here: [Repeating a repeated sequence](http://stackoverflow.com/questions/11180125/repeating-a-repeated-sequence) – Miha Mar 12 '17 at 21:12
  • @Miha The link you provided does not include `seq` – Pierre Lapointe Mar 12 '17 at 21:14
  • @P Lapointe the point of my comment was that with the little effort he could found the answer to his question. – Miha Mar 12 '17 at 21:17

2 Answers2

2

This will work:

rep(seq(0,4.8,by=0.8),each=3)
[1] 0.0 0.0 0.0 0.8 0.8 0.8 1.6 1.6 1.6 2.4 2.4 2.4 3.2 3.2 3.2 4.0 4.0 4.0 4.8 4.8 4.8
Pierre Lapointe
  • 16,017
  • 2
  • 43
  • 56
0
mySeq <- c()
for (i in seq(0, 4.8, by = 0.8)) {
    mySeq <- c(mySeq, rep(i, 3))
}

mySeq
[1] 0.0 0.0 0.0 0.8 0.8 0.8 1.6 1.6 1.6 2.4 2.4 2.4 3.2 3.2 3.2 4.0 4.0 4.0 4.8 4.8 4.8
Matin Kh
  • 5,192
  • 6
  • 53
  • 77