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
One way:
v = 1981:1984
v[ sequence(rev(seq_along(v))) ]
# [1] 1981 1982 1983 1984 1981 1982 1983 1981 1982 1981
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With