Re: [R] Non repetitive permutations/combinations of elements

From: Gabor Csardi <csardi_at_rmki.kfki.hu>
Date: Tue 09 May 2006 - 07:53:09 EST

Alternate solution with the combinat package:

m <- hcube(c(2, 2, 2))
m[m==1] <- -1
m[m==2] <- 1

Gabor

On Mon, May 08, 2006 at 03:45:37PM -0600, Greg Snow wrote:
> Try expand.grid:
>
> expand.grid( c(-1,1), c(-1,1), c(-1,1) )
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.snow@intermountainmail.org
> (801) 408-8111
>
>
> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Nameeta Lobo
> Sent: Monday, May 08, 2006 3:33 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Non repetitive permutations/combinations of elements
>
>
> Hello all,
>
> I am trying to create a matrix of 1s and -1s without any repetitions for
> a specified number of columns.
> e.g. 1s and -1s for 3 columns can be done uniquely in 2^3 ways.
> -1 -1 -1
> -1 -1 1
> -1 1 -1
> -1 1 1
> 1 -1 -1
> 1 -1 1
> 1 1 -1
> 1 1 1
> and for 4 columns in 2^4 ways and so on.
>
> I finally used the function combn([0 1],3) that I found at the following
> link
> http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId
> =7147&objectType=FILE
> written by Jos van der Geest in Matlab which generated the above.
>
>
> How can I do this is R? I have looked at permn and combn in the combinat
> library and permutations and combinations in the gtools library and I am
> still confused as to how to get it to work.
>
> Any suggestions will be truly appreciated.
>
> Thank you
>
> Nameeta
>
>
>
> -------------------------------------------------
> This email is intended only for the use of the individual\ o...{{dropped}}
>
> ______________________________________________
> 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

-- 
Csardi Gabor <csardi@rmki.kfki.hu>    MTA RMKI, ELTE TTK

______________________________________________
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 09 08:09:00 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 09 May 2006 - 10:10:05 EST.

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