Search code examples
rlistsequencerepeat

I want to create a list in R where I repeat the numbers in a sequence X amount of times whilst it counts chronologically?


I have a long table of let's say 198 variables. I would like to insert an ID column where R counts for me from 1-22 chronologically, repeating each count 9 times. (198/22=9)

In other words I want the sequence to go : 1 (9 times), 2 (9 times), 3(9 times) until it reaches 22 (9 times). I have already tried different ways but have not been able to figure it out. Thank you so much in advance.


Solution

  • We can use rep

    rep(1:22, each = 9)