Creating a repeating vector sequence in R [duplicate]

半腔热情 提交于 2019-12-01 10:19:26

问题


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.


回答1:


Try this:

rep(1:4,4:1)

Output:

[1] 1 1 1 1 2 2 2 3 3 4



回答2:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!