[R] How sample without replacement on more than one variables?

Bernardo Rangel Tura tura at centroin.com.br
Sun May 23 12:47:04 CEST 2010


On Sun, 2010-05-23 at 00:56 -0700, dusadrian wrote:
> This might help, depending on your exact needs:
> > v1 <- sample(letters[1:2], 10, replace=TRUE)
> > v2 <- sample(letters[3:4], 10, replace=TRUE)
> > v3 <- sample(letters[5:6], 10, replace=TRUE)
> > aa <- data.frame(v1=v1, v2=v2, v3=v3)

And now is simple, sample the row of data frame
aa[sample(1:nrows(aa),3),]


-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil



More information about the R-help mailing list