random sampling problems?
with replacement or not ?
without replacement:
data1 <- cbind(id=1:9, expand.grid(x=1:3,y=1:3))
merge(data1, sapply(data1[,c("x","y")], sample, 3), all.y=T)
why not:
data1[sample(data1$id, 3),]
-------------------------------------------------------------------
Jacques VESLOT
CNRS UMR 8090
I.B.L (2?me ?tage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex
Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31
http://www-good.ibl.fr
-------------------------------------------------------------------
zhijie zhang a ?crit :
Dear friends,
suppose my dataset is the following data:
id<-1:9
x<-c(1,2,3,1,2,3,1,2,3)
y<-c(1,1,1,2,2,2,3,3,3)
data<-data.frame(id,x,y)
id x y
1 1 1 1
2 2 2 1
3 3 3 1
4 4 1 2
5 5 2 2
6 6 3 2
7 7 1 3
8 8 2 3
9 9 3 3
i want to do sampling like this:say the sample size is 3.
First: random sampling from x;
Next ,random sampling from y ;and combing sampled x and sampled y;
Finally, output the samples: id x and y.
I think i could call it two-dimension sampling.
Thanks very much!