[R] How sample without replacement on more than one variables?
dusadrian
dusa.adrian at gmail.com
Sun May 23 09:56:46 CEST 2010
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)
> aa
v1 v2 v3
1 a d e
2 a d e
3 a c e
4 b d e
5 b d f
6 a c f
7 a c f
8 a c f
9 a c e
10 b c e
> bb <- unique(aa)
> bb
v1 v2 v3
1 a d e
3 a c e
4 b d e
5 b d f
6 a c f
10 b c e
You can sample from the "bb" dataframe, or from the corresponding rows of
the "aa" dataframe that are unique (1, 3, 4, 5, 6 and 10) which can be
obtained via rownames(bb).
Hth,
Adrian
--
View this message in context: http://r.789695.n4.nabble.com/How-sample-without-replacement-on-more-than-one-variables-tp2227665p2227683.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list