[R] Conditional sampling?

Olga Lyashevska olga at herenstraat.nl
Thu Feb 4 14:40:55 CET 2010


Thanks Thierry!

On 04.02.2010, at 13:22, ONKELINX, Thierry wrote:

> selection <- subset(somedf, col1 != "a")
> sample(selection$col2, 2, replace = TRUE)


I simplified it, but in fact it is not only 'a' to be eliminated, but  
thousands of  rows.

Can I use:

col1sample<-sample(col1,2,replace=T)
selection <- subset(somedf, col1= col1sample) # why do we say here  
somedf, cant we just restrict our condition to one row only?

I was also thinking of doing something like:

col1sample<-sample(col1,2,replace=T)
col2selection<-col2[col1==col1sample]
col2sample<-sample(col2selection,2,replace=T)

Does it make sense?



More information about the R-help mailing list