[R] Writing a Permutation Function
petermec
petermec at buffalo.edu
Sun Apr 29 14:29:05 CEST 2012
Thanks for all the suggestions. This is my final code that seems to be
working:
alphabet = c("a","b","c","d")
holder = c()
permute = function(alphabet,n){
while((length(unique(holder))/n)<(length(alphabet)^n)){
perm = sample(alphabet, replace=T, size=n)
holder = rbind(holder, perm, deparse.level=0)
}
data2 = unique(holder)
data3 = data2[order(data2[,1],data2[,2]),]
labels = apply(data3, 1, paste, sep="", collapse="")
print(data.frame(data3, row.names=labels))
}
Is this an efficient enough method?
--
View this message in context: http://r.789695.n4.nabble.com/Writing-a-Permutation-Function-tp4594621p4596297.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list