Question:
I want to generate a sequence where in a first step a random start number is chosen. Depending on the random start number (let’s say:start_number = 3
) I want to generate the following sequence. How can I do this?Since you said your start is random, here is a code to do this:
seq_length <- 4 start_number <- sample(seq_length, 1) b <- start_number:seq_length rep(c(b, setdiff(1:seq_length, b)), each = 2, length=100) [1] 2 2 3 3 4 4 1 1 2 2 3 3 4 4 1 1 2 2 3 3 4 4 .... [/code]
If you have better answer, please add a comment about this, thank you!