##### ## A function to get all permutations on numElem elements. ## There is nothing sophisticated about this. Thus, it ## is rather slow. Also, because of how the permutations ## are stored, the upper limit depends on your machine. ## ## Use: ## getPermutations(17) getPermutations <- function(numElem) { perm=matrix(NA,ncol=numElem,nrow=2^numElem) for(x in 0:(2^numElem-1) ) { mm = numElem-1 dd = paste(rev(as.integer(intToBits(x))), collapse="") nn = nchar(dd) st = substring(dd, nn-mm,nn) perm[(x+1),] = as.numeric(unlist(strsplit(st,split=""))) } return(perm) }