[R] Selecting subsamples

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Thu Dec 4 15:08:48 CET 2003


On 04-Dec-03 christian_mora at vtr.net wrote:
> Hi all,
> I?m working with a dataset with 9 columns and 2000 rows. Each row
> represents an individual and one of the columns represents the volume
> of that individual (measured in cubic meters). I?d like to select a
> sample from this dataset (without considering any probability of the
> rows) in which the sum of the volume of the individuals in that sample
> >= 100 cubic m.

let X be the dataset. For N=2000:

  ix<-sort(rnorm(N),index.return=TRUE)$ix

  M<-max(which(cumsum(volume[ix])<100))+1 ## Assumes volume > 0

  X[ix[1:M],]

If you can't assume volume > 0, then somthing like

  M<-min( which(sum(volume)-cumsum(volume[ix]) <= sum(volume) - 100) )

Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 04-Dec-03                                       Time: 14:08:48
------------------------------ XFMail ------------------------------




More information about the R-help mailing list