Re: [R] Fw: random sampling steps in R with replacement

From: andrija djurovic <djandrija_at_gmail.com>
Date: Thu, 10 Mar 2011 11:05:56 +0100

Hi Taby,

this is not best solution for sure but it will give you, maybe, some ideas :)
I am also looking forward to see other solutions.

data<-data.frame(id=1:(165+42),x=rep(c("male","female"),c(42,165))) f<-function(x) {
str.sample<-list()
for (i in 1:length(levels(x$x)))
{
str.sample[[i]]<-x[x$x==levels(x$x)[i]
,][sample(tapply(x$x,x$x,length)[i],20,rep=T),] }
strat.sample<-do.call("rbind",str.sample) return(strat.sample)
}
f(data)
repl<-list()
for(i in 1:1000)
{
repl[[i]]<-f(data)
}
repl

Andrija

On Thu, Mar 10, 2011 at 10:04 AM, taby gathoni <tabieg_at_yahoo.com> wrote:

> Please note is with replacement
>
>
>
> From: taby gathoni <tabieg_at_yahoo.com>
> To: R help <r-help_at_r-project.org>
> Sent: Thursday, March 10, 2011 11:53 AM
> Subject: [R] random sampling steps in R
>
> Dear all,
>
> Could someone assist me in random sampling steps/code in R? I have a main
> sample of 42 males and 165 females and I want to come up with about 1000
> samples of 20 males and 20 females from this main sample. While at it, i
> would also like to come up Accuracy Ratios (ARs) with corresponding
> confidence intervals.
>
> Please assist.
>
>
> Thanks so much,
>
> Taby
>
>
>
> [[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<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<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 Thu 10 Mar 2011 - 10:12:36 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 Mon 14 Mar 2011 - 14:20:21 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.

list of date sections of archive