Re: [R] Multiset Permutations

From: Johannes Hüsing <johannes_at_huesing.name>
Date: Sun, 06 Apr 2008 23:49:54 +0200

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.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 06 Apr 2008 - 21:53:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 07 Apr 2008 - 00:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive