[R] Sampling

Daniel Nordlund res90sx5 at verizon.net
Tue Feb 5 20:12:53 CET 2008


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Judith Flores
> Sent: Tuesday, February 05, 2008 10:52 AM
> To: RHelp
> Subject: [R] Sampling
> 
> Hi there,
> 
>    I want to generate different samples using the
> followindg code:
> 
> 
> g<-sample(LETTERS[1:2], 24, replace=T)
> 
>    How can I specify that I need 12 "A"s and 12 "B"s?
> 
> Thank you,
> 
> Judith
> 
> 

Judith,

Does this do what you want?

   g<-sample(rep(LETTERS[1:2],12))

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA  USA



More information about the R-help mailing list