[R] Conditional Random selection

Ashta sewashm at gmail.com
Sat Nov 21 18:52:39 CET 2015


Hi all,

I have a data set that contains samples collected over time.   In
each time period the total number of samples are given (X2)   The goal
is to  select 500  random samples.    The selection should be based on
time  (select time periods until I reach 500 samples). Also the time
period should have greater than 0 for  X1 variable. X1 is an indicator
variable.

Select "time" until reaching the  sum of X2  is > 500 and if   X1 is  >  0

tab  <- read.table(textConnection(" time   X1 X2
1      0        251
2      5        230
3      1        300
4      0         25
5      2         10
6      3         101
7      1         300
 8     4         185   "),header = TRUE)

In the above example,  samples from time 1 and 4  will not be selected
( X1 is zero)
So I could reach my target by selecting time 6,7, and 8 or  time 2 and
3 and so on.

Can any one help to do that?



More information about the R-help mailing list