R rep function with for loop

I have a valid range of 1981: 1984. How to use the rep () function to obtain the following results: For each round representative, the last year falls: first come 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
+4
source share
1 answer

One of the methods:

v = 1981:1984
v[ sequence(rev(seq_along(v))) ]
# [1] 1981 1982 1983 1984 1981 1982 1983 1981 1982 1981
+8
source

Source: https://habr.com/ru/post/1673918/


All Articles