4

I have a year range 1981:1984. How can use rep() function to get the following results: For each round rep, the latest year is dropped off: first get 1981:1984, then 1981:1983, then 1981:1982, then 1981 as shown in the table:

1981
1982
1983
1984
1981
1982
1983
1981
1982
1981
Frank
  • 66,179
  • 8
  • 96
  • 180
dennis
  • 119
  • 1
  • 8

1 Answers1

8

One way:

v = 1981:1984
v[ sequence(rev(seq_along(v))) ]
# [1] 1981 1982 1983 1984 1981 1982 1983 1981 1982 1981
Frank
  • 66,179
  • 8
  • 96
  • 180