RE: [R] vectorized approach to cumulative sampling

2005-04-07 Thread Ted Harding
On 07-Apr-05 Daniel E. Bunker wrote: > Hi All, > > I need to sample a vector ("old"), with replacement, up to the point > where my vector of samples ("new") sums to a predefined value > ("target"), shortening the last sample if necessary so that the total > sum ("newsum") of the samples matches

Re: [R] vectorized approach to cumulative sampling

2005-04-07 Thread Rich FitzJohn
Hi, sample() takes a "replace" argument, so you can take large samples, with replacement, like this: (In the sample() call, the 50*target/mean(old) should make it sample 50 times more than likely. This means the while loop will probably get executed only once. This could be tuned easily, and ther

[R] vectorized approach to cumulative sampling

2005-04-07 Thread Daniel E. Bunker
Hi All, I need to sample a vector ("old"), with replacement, up to the point where my vector of samples ("new") sums to a predefined value ("target"), shortening the last sample if necessary so that the total sum ("newsum") of the samples matches the predefined value. While I can easily do this