[R] Sampling
Daniel Nordlund
djnordlund at frontier.com
Mon Mar 30 08:23:45 CEST 2015
On 3/29/2015 11:10 PM, Partha Sinha wrote:
> I have 1000 data points. i want to take 30 samples and find mean. I
> also want to repeat this process 100 times. How to go about it?
> Regards
> Parth
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
see ?replicate and ?sample. Simple example where yourdata is a simple
vector of values, and assuming you want to sample without replacement.
Generalizing it to other data structures is left as an exercise for the
reader.
replicate(100,mean(sample(yourdata,30, replace=FALSE)))
hope this is helpful,
Dan
--
Daniel Nordlund
Bothell, WA USA
More information about the R-help
mailing list