Re: [R] random sampling problems?

From: Jacques VESLOT <jacques.veslot_at_good.ibl.fr>
Date: Tue 04 Jul 2006 - 18:22:15 EST

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!
>
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 04 18:26:47 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 04 Jul 2006 - 20:15:24 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.