This question already has an answer here:
I need some help. How to create the following vector sequence:
1 1 1 1 2 2 2 3 3 4
I tried to use (rep) and (seq) but still unsucessfull.
Try this:
rep(1:4,4:1)
Output:
[1] 1 1 1 1 2 2 2 3 3 4
or less concisely: c(rep(1, 4), rep(2,3), rep(3, 2), 4)
output: [1] 1 1 1 1 2 2 2 3 3 4
来源:https://stackoverflow.com/questions/46167499/creating-a-repeating-vector-sequence-in-r