Hello,

I was wondering if anyone can think of a straightforward way (without
loops) to do the following shuffling:

Let's imagine a vector:
c(1,1,1,2,2,3,3,3)

I would like to derive shuffled vectors __where the same digits are
never separated__, although they can be at both ends (periodicity).

So the following shuffled vectors are possible:

c(2,2,1,1,1,3,3,3)
c(2,1,1,1,3,3,3,2)
c(3,3,3,1,1,1,2,2)
c(3,1,1,1,2,2,3,3)
etc ...

I should mention that there can be any number of different numbers,
and any number of repetition of each number.

So the vectors I have to deal with could look like
c(1,1,2,3,4,5,6,6,6,6,6,6,6,6,7,8) for example

Since I have to derive many shuffled versions for each vector, I am
looking for an efficient way of doing it. Can you think of a way
without nested loops?

Many thanks for your help,

Best,

Emmanuel

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to