Re: [R] (no subject)

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Mon, 17 Nov 2008 12:31:44 -0700

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.
______________________________________________ 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 17 Nov 2008 - 19:35:59 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 17 Nov 2008 - 20:30:26 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