Re: [R] Sampling

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Tue, 05 Feb 2008 14:04:19 -0500

On 2/5/2008 1:52 PM, Judith Flores wrote:
> 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

x <- rep(c("A","B"), each=12)

x
  [1] "A" "A" "A" "A" "A" "A" "A" "A" "A" "A" "A" [12] "A" "B" "B" "B" "B" "B" "B" "B" "B" "B" "B" [23] "B" "B"

# "sample(x) generates a random permutation of the elements of x"

g <- sample(x)

g
  [1] "A" "A" "B" "A" "B" "B" "B" "B" "A" "B" "A" [12] "A" "B" "A" "A" "A" "B" "B" "B" "A" "A" "B" [23] "A" "B"

> ____________________________________________________________________________________
> Be a better friend, newshound, and
>
> ______________________________________________
> 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.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

______________________________________________
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 Tue 05 Feb 2008 - 19:08:06 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 Tue 05 Feb 2008 - 19:30:14 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