Skip to content

vector

3 messages · Hamid Hamid, David Winsemius, Charles C. Berry

#
> samp <- sample(pop, 2, replace=FALSE)
 > samp
[1] 14  9
 > pop2<- pop[!pop %in% samp]
 > pop2
[1]  1  5  7 12 18 19 65 54
On Dec 1, 2008, at 2:29 PM, Hamid Hamid wrote:

            
#
On Mon, 1 Dec 2008, Hamid Hamid wrote:

            
You mean ONLY 'after each sample is taken'? That is,  you sample with 
replacement, then remove the sample from the population, sample again with 
replacement and then remove those, ...

If that is not what you mean, ordinary sampling WOR will do.

If the scheme I describe above is what you meant, read on.

Sometimes it is efficient to vectorize in a way that yields an incomplete 
answer, then patch the result, then patch the patched result, ...

Here is an example that implements drawing samples with replacement, but 
removing each sample before drawing the next (so a single sample could 
contain duplicates, but no pair of samples could contain the same 
element):
[1] 0
Obviously, you would build the part after the 'trials <-' line  into a 
while(){} loop , and you can easily improve upon 'setdiff( pop, trials )'.

HTH,

Chuck
Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901