# For what it's worth (was Re: [R] Permutations).

From: Rolf Turner <rolf_at_math.unb.ca>
Date: Wed 14 Jul 2004 - 08:37:05 EST

For what it's worth, here is a mild revision of my restr.perm() function, which seems NOT to fall over. I.e. it appears to ``reliably'' generate restricted permutations.

Whether these are genuinely ***random*** restricted permutations (i.e. does each restricted permutation of 1:12 have the same probability of being generated?) is not clear to me. So ***DON'T TRUST IT***!!! ===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+=== restr.perm <- function ()
{

```S <- 4:12
G <- NULL
A <- list(1:3,4:6,7:9,10:12)
for(k in 1:4) {
for(i in A[[k]]) {
tmp <- union(i,S)
tmp <- setdiff(tmp,G)
if(length(tmp)==0) return(Recall())
x <- if(length(tmp)==1) tmp else sample(tmp,1)
G <- c(G,x)
S <- setdiff(S,G)
}
S <- union(S,A[[k]])
R <- if(k < 4) A[[k+1]] else NULL
R <- union(R,G)
S <- setdiff(S,R)
```

}

G
}

===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===

cheers,

```					Rolf Turner
rolf@math.unb.ca

______________________________________________
```
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jul 14 08:52:27 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:56 EST