[R] Unique arrangements of a vector

From: Tarmo Remmel <tarmo.remmel_at_utoronto.ca>
Date: Tue 31 May 2005 - 05:50:10 EST

Dear List,

Running on a PC (Windows 2000) with 256 MB RAM, Version R1.9.1

I have a relatively simple problem, which I can solve for relatively small datasets, but run into difficulties with larger ones. I believe that my approach is a hack rather than something elegant and I was hoping that somebody on this list might help me improve my code. Basically, given a vector of values (e.g., 0,0,1,1), I want to generate all of the unique arrangements of these values, of which there are 4!/(2!2!) = 6.

0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0

Using unique() in conjunction with expand.grid(), and later filtering impossible results, I can obtain the answer. However, this is slow, and does not work for large initial vectors and is difficult to filter when using values beyond 0,1. Is there some mathematically elegant method for doing this? I'd hope to have initial vectors significantly longer than the demonstrated 4 values (e.g., thousands).

Any help is appreciated and I will gladly SUM afterwards.

Thank you,


Tarmo Remmel Ph.D.
GUESS Lab, Department of Geography
University of Toronto at Mississauga
Mississauga, Ontario, L5L 1C6
Tel: 905-828-3868
Fax: 905-828-5273
Skype: tarmoremmel

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue May 31 05:56:46 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:16 EST