[R] Multiset Permutations

Johannes Hüsing johannes at huesing.name
Sun Apr 6 23:49:54 CEST 2008


You can use the function permutation from the e1071 package,
then

library(e1071)

multisetperm <- function(multiset) { 
unique(apply(matrix(multiset[permutations(length(multiset))], 
ncol=length(multiset)), 1, paste, sep="", collapse="")) }
multisetperm(c("0", "0", "1", "2", "2"))

> The output would look something like this:
>
> 00122
> 01220
> 01210
> 20201
> 10202
> 12200
> etc...
>
>
The Java algorithm you cited does not look any more clever or less 
wasteful
than this.



More information about the R-help mailing list