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 [EMAIL PROTECTED] 801.408.8111 > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > project.org] On Behalf Of Salas, Andria Kay > Sent: Monday, November 17, 2008 8:54 AM > To: r-help@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@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@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.