Creating a repeating vector sequence in R [duplica

2020-03-30 05:13发布

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.

标签: r seq rep
2条回答
淡お忘
2楼-- · 2020-03-30 05:58

Try this:

rep(1:4,4:1)

Output:

[1] 1 1 1 1 2 2 2 3 3 4
查看更多
▲ chillily
3楼-- · 2020-03-30 06:03

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

查看更多
登录 后发表回答