[R] sampling without repetition
Thomas W Blackwell
tblackw at umich.edu
Tue Nov 18 02:13:18 CET 2003
Rajarshi -
To obtain three disjoint subsets, I would do
indic <- sample(seq(3), length(r), TRUE)
s1 <- r[indic == 1]
s2 <- r[indic == 2]
s3 <- r[indic == 3]
Note that the sizes of the three subsets have a
joint multinomial distribution with parameters
prob = c(1/3, 1/3, 1/3) and n = length(r).
- tom blackwell - u michigan medical school - ann arbor -
On Mon, 17 Nov 2003, Rajarshi Guha wrote:
> On Mon, 2003-11-17 at 20:01, Thomas W Blackwell wrote:
> > Rajarshi -
> >
> > Do you want three sets, three disjoint sets, or sets of
> > size three ? It's not clear what you are attempting to do.
>
> Sorry about that. I wanted to select 3 disjoint sets from a supplied
> vector of numbers. My initial example had
>
> r <- 1:300
>
> but there is no guarantee that r will contain a consecutive sequence of
> numbers.
>
> -------------------------------------------------------------------
> Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
> GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
> -------------------------------------------------------------------
>
> A list is only as strong as its weakest link.
> -- Don Knuth
>
>
More information about the R-help
mailing list