[R] Random Sequence

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Apr 12 23:36:26 CEST 2007


Anup Nandialath wrote:
> Dear Friends,
>
> I'm trying to generate a sequence of 100 observations
> with either a 1 or -1. In other words the sequence
> should look something like this.
>
> y = 1 1 -1 1 -1 -1 -1 1 1 ......
>
> Can somebody please give me some direction on how I
> can do this in R.
>   
sample(c(-1, 1), 100, replace=TRUE)



More information about the R-help mailing list