# [R] Permutations

Robin Hankin rksh at soc.soton.ac.uk
Thu Jul 15 10:14:48 CEST 2004

```hi again

what a stimulating R discussion!  This is R-help at its very best!

I think I understand why you don't want pure inter-block permutations.

My solution would be to realize that weeding out "forbidden" permutations is
quite difficult and time-consuming (also as several people have pointed out
forbidden permutations are very rare, accounting for only a proportion of

The extra expense of this weeding process
is likely to outweigh the slight loss of efficiency caused by
generating a forbidden permutation.  My solution would therefore be:

x <- c(1,2,3,4,5,6,7,8,9,10,11,12)
x.new <- sample(x)

(note the not-inconsiderable advantage of code simplicity!)

I think my algorithm generated repeats because in
it there are only (4!)^3=13284 distinct
permutations; see help(birthday).  The system
above has 12! ~= 4x10^8, much higher.

Hope this helps

Robin

>
>}
>7.- Robin Hankin
>a<-matrix(1,200,12)
>for (i in 1:200)
>{
>x <- c(1,2,3,4,5,6,7,8,9,10,11,12)
>dim(x) <- c(3,4)
>  jj <- t(apply(x,1,sample))
>a[i,]<-as.vector(jj)
>}
>##In 200 permutations, there are 5 repetitions.
>
>Thanks to all and sorryfor the confusion that
>have generated the "intra-block" permutation.
>
>Jordi Altirriba
>PhD student
>Hospital Clinic - Barcelona - Spain
>
>P.S. I think that I don't have forgot to anybody...(sorry if I have done it)
>
>_________________________________________________________________
>¿Cuánto vale tu auto? Tips para mantener tu
>carro. ¡De todo en MSN Latino Autos!
>http://latino.msn.com/autos/

--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743
initialDOTsurname at soc.soton.ac.uk (edit in obvious way; spam precaution)

```