[R] Repeaded sampling

Eik Vettorazzi E.Vettorazzi at uke.uni-hamburg.de
Thu Feb 10 22:02:09 CET 2011


Hi,
try

ds<-1:50
M<-10
n<-sample(5:15,M,replace=T)  #generate different n[i]
lapply(1:M,FUN=function(i) sample(ds,n[i]))

hth.

Am 10.02.2011 19:50, schrieb Hui Du:
> 
> Hi all,
> 
>                 I have a dataset. Each time I want to sample N(i) elements from it and I want to repeated sampling M times. N(i) is varied from time to time. For example,
> 
>                 dataset = 1:50;
>                 a = list();
> 
>                 M = 1000;
> 
>                 I want to do something like
>                 for(i in 1:M)
> 
> {
>                 a[[i]] = sample(dataset, sample(length(dataset), 1))
>                 }
> 
>                 But my question is that if there is more elegant solution for this, for example, without bothering loop, can I do the repeated sampling?
> 
>                 Many thanks.
> 
> 
> HXD
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790



More information about the R-help mailing list