I am trying to take a vector of numbers 5:0 and repeat it 3 times, every other time reversing its order

I'd think this would be simple using the rev() and seq() functions, but am struggling to get the reverse order part correct.

I'm trying to get 5432101234543210 from 5:0.

Not too hard to set as a function...

try_it <- function(x) {

  c(rev(x), x[2:length(x-1)], rev(x)[2:length(x-1)])

}

try_it(0:5)

# [1] 5 4 3 2 1 0 1 2 3 4 5 4 3 2 1 0

Edit

Extend function to have variable repeats

try_it <- function(x, reps) {

  c(rev(x), rep(c(x[2:length(x-1)], rev(x)[2:length(x-1)]), (reps - 1) / 2))

}

try_it(0:5, 5)

# [1] 5 4 3 2 1 0 1 2 3 4 5 4 3 2 1 0 1 2 3 4 5 4 3 2 1 0

Note: I've not worked hard to generalise this extension, it will not return the correct length for an even number of repetitions. I'm sure you could modify to suit your requirements.