Creating a repeating vector sequence in R [duplicate]
问题 This question already has an answer here : R: generate a repeating sequence based on vector (1 answer) Closed 2 years ago . 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