[R] (no subject)

Greg Snow Greg.Snow at imail.org
Mon Nov 17 20:31:44 CET 2008


This gives a data frame rather than a matrix, but you can convert it:

x <- do.call( expand.grid, rep( list( c(-1,1) ), 20 ) )

hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Salas, Andria Kay
> Sent: Monday, November 17, 2008 8:54 AM
> To: r-help at r-project.org
> Subject: [R] (no subject)
>
> I need help generating all possible combination of a vector of randomly
> assigned values of 1 and -1.  For example, a vector of 20 randomly
> placed 1s and -1s, and all possibilities (which would amount to 2^20
> total vectors).  I am able to generate one such vector (via sample(c(-
> 1,1),20,replace=TRUE)), but I do not know how to generate all the
> possibilities, which would need to be placed in a matrix.  Any help
> would be greatly appreciated!!!
> ______________________________________________
> 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.



More information about the R-help mailing list