[R] Sample Function

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Thu Jul 16 19:37:16 CEST 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of MarcioRibeiro
> Sent: Thursday, July 16, 2009 8:56 AM
> To: r-help at r-project.org
> Subject: [R] Sample Function
> 
> 
> Hi listers,
> Suppose I have a dataset with n=10 observations and I want to sample with
> replacement.
> My new sample is of size m=9.
> So, I am using the following code...
> newsample<-dataset[sample(m,replace=T),]
> The problem is that generates the new sample and the last observation of my
> data set is never included.
> I can sample the identification like this code...
> newsample<-sample(1:n,m,replace=TRUE)
> But, after this code I am obtaining a statistic and I have only the
> identification of the data observed.
> Is there a way that I can sample the data observed to calculate a statistic
> of it.
> Thanks in advance,
> Marcio

Try

newsample<-dataset[sample(1:10,m,replace=TRUE),]

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204




More information about the R-help mailing list