[R] Random Sequence

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Thu Apr 12 23:52:30 CEST 2007


> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Matthew Keller
> Sent: Thursday, April 12, 2007 2:32 PM
> To: Anup Nandialath
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] Random Sequence
> 
> Hi Anup,
> 
> (runif(100)<.5)*1   #would give you 0's and 1's.
> 
> sample(rep(c(-1,1),50),100)  #A bit slower I think, gives you 
> -1's and 1's
> 

How about

  sample(c(-1,1), 100, replace=TRUE) 

Hope this is helpful,

Dan

Daniel J. Nordlund
Research and Data Analysis
Washington State Department of Social and Health Services
Olympia, WA  98504-5204



More information about the R-help mailing list