[R] All possible permutations of a 3 group assignment vector
Duplisea, Daniel
Daniel.Duplisea at dfo-mpo.gc.ca
Mon Jun 21 18:50:30 CEST 2010
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
More information about the R-help
mailing list