# Re: [R] Sampling with replacement

From: William Dunlap <wdunlap_at_tibco.com>
Date: Wed, 16 Jun 2010 13:12:27 -0700

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Somnath Somnath
> Sent: Wednesday, June 16, 2010 10:28 AM
> To: r-help_at_r-project.org
> Subject: Re: [R] Sampling with replacement
>
> Thanks for all those reply. Is there any general rule to
> determine how many
> samples I would get from a population of size "n", I draw a

> sample of size
> "m" ("m" may be greater than "n") if sample is drawn with replacement?

If you consider two samples equivalent if they differ only in their ordering (e.g., c(1,2,2) is equivalent to c(2,1,2) and c(2,2,1)) then the answer is

choose(n+m-1, m)
If order matters then it is

n^m

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

> Thanks,
>
> 2010/6/16 Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
>
> > Hi Rafael,
> >
> > You might try:
> >
> > > r <- expand.grid(rep(list(1:20), 4))
> > > dim(r)
> > [1] 160000 4
> >
> > HTH,
> > Jorge
> >
> >
> > 2010/6/16 Rafael Björk <>
> >
> >> If you for some reason want to be shown all the possible
> combinations, try
> >> expand.grid(1:20,1:20,1:20,1:20) (ugly code). Don't use
> this for sampling.
> >>
> >> hth Rafael
> >>
> >> 2010/6/16 Jorge Ivan Velez <>
> >>
> >> Try
> >>>
> >>> sample(20, 4, replace = TRUE)
> >>>
> >>> HTH,
> >>> Jorge
> >>>
> >>>
> >>> On Wed, Jun 16, 2010 at 10:20 AM, Somnath Somnath <> wrote:
> >>>
> >>> > Dear all, good morning,
> >>> >
> >>> > I have a population, let say members are tagged with
> some simple number
> >>> > like
> >>> > 1,2,3,...20. I want to draw a sample with replacement
> of size 4 (say,
> >>> can
> >>> > be
> >>> > more than 20 also). Is there any R function which will
> show me all such
> >>> > possible samples?
> >>> >
> >>> > Thanks
> >>> >
> >>> > [[alternative HTML version deleted]]
> >>> >
> >>> > ______________________________________________
> >>> > R-help_at_r-project.org mailing list
> >>> > https://stat.ethz.ch/mailman/listinfo/r-help
> >>> > http://www.R-project.org/posting-guide.html
> >>> > and provide commented, minimal, self-contained,
> reproducible code.
> >>> >
> >>>
> >>> [[alternative HTML version deleted]]
> >>>
> >>> ______________________________________________
> >>> R-help_at_r-project.org mailing list
> >>> https://stat.ethz.ch/mailman/listinfo/r-help
> >>> http://www.R-project.org/posting-guide.html
> >>> and provide commented, minimal, self-contained, reproducible code.
> >>>
> >>
> >>
> >
>
> [[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. Received on Wed 16 Jun 2010 - 20:17:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Jun 2010 - 20:31:25 GMT.

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