Creating a repeating vector sequence in R

2.2k views Asked by At

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.

2

There are 2 answers

0
www On

Try this:

rep(1:4,4:1)

Output:

[1] 1 1 1 1 2 2 2 3 3 4
0
dbo On

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