1

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.

Daisy
  • 39
  • 3
  • 1
    See these two also : [1](https://stackoverflow.com/questions/11180125/repeating-a-repeated-sequence) & [2](https://stackoverflow.com/questions/3102777/r-generate-a-repeating-sequence) – user2100721 Sep 12 '17 at 03:47
  • 1
    @Sotos Here is a fun one for this particular problem: `sort(sequence(1:4))`. – lmo Nov 01 '17 at 20:24

2 Answers2

4

Try this:

rep(1:4,4:1)

Output:

[1] 1 1 1 1 2 2 2 3 3 4
www
  • 4,124
  • 1
  • 11
  • 22
0

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

dbo
  • 1,174
  • 1
  • 11
  • 19