[R] Extract values from data frame in R

David Winsemius dwinsemius at comcast.net
Mon Aug 9 08:27:39 CEST 2010


On Aug 9, 2010, at 2:16 AM, Alexander Eggel wrote:

> Using R, I would like to find out which Samples (S1, S2, S3, S4, S5)  
> fulfill
> the following criteria:contain minimally one value (x, y or z)  
> bigger than
> 4. Any ideas? Thanks, Alex.
>
>> data
>  Sample       x        y      z
> 1        S1   -0.3    5.3    2.5
> 2        S2    0.4    0.2   -1.2
> 3        S3    1.2   -0.6    3.2
> 4        S4    4.3    0.7    5.7
> 5        S5    2.4    4.3    2.3
>

data$Sample[apply(data[, -1], 1, function(xyz) any(xyz > 4))]
[1] "S1" "S4" "S5"


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list