[R] All possible permutations of a 3 group assignment vector

From: Duplisea, Daniel <Daniel.Duplisea_at_dfo-mpo.gc.ca>
Date: Mon, 21 Jun 2010 12:50:30 -0400

Hello. Given this group assignment vector x:

x= rep(letters[1:3],c(9,21,9))

I would like to know the number of all possible unique permutations of x and also obtain the matrix of them. Thus, each vector should still contain 9*a, 21*b and 9*c, but case assigment must be different for one case (default at least 2) for each permuation. a, b and c can be interspersed in permuted vectors, i.e. order does not matter. If this unique permutation matrix is very large then I would like to choose a subset of it. I can easily permute the vector with sample(x) but if I repeat this n>1 times there is no guarantee of uniqueness. For a small number of samples, I could look for unique vectors and keep only those but this seems awkward and I suspect there are more elegant ways to do it.

Is there an r function which will allow me to calculate both how many unique permutations of x exist and also obtain a matrix of them and/or a subset of that matrix?

Thanks very much,
Daniel



Daniel Duplisea
Pêches et Océans / Fisheries and Oceans Canada Institut Maurice-Lamontagne
Mont-Joli, QC
G5H 3Z4
Canada  

tel: 1 418 775 0881
fax: 1 418 775 0740



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 Mon 21 Jun 2010 - 16:52:54 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 21 Jun 2010 - 21:30:34 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