Minimum value of a line excluding zero values (R)

4
    TIMP3 TOTS3      UGPA3     USIM5     VALE3     VALE5    VIVT4 VLID3     WEGE3

1 0.7941716     0 0.00915221 0.2751215 0.3803796 0.5162442 1.505921     0 0.5559166

2 0.7710909     0 0.09351134 0.3925726 0.3687917 0.5158750 1.469548     0 0.5389812

3 0.7634292     0 0.10535813 0.4906756 0.3575568 0.5170484 1.433848     0 0.5225616

4 0.7479777     0 0.26867319 0.5142030 0.3754794 0.5018268 1.407619     0 0.5066423

5 0.7520354     0 0.29342233 0.6426008 0.4840935 0.6466121 1.400813     0 0.4912079

6 0.7559319     0 0.28448351 0.6571724 0.4694412 0.6365194 1.360621     0 0.4762438

I'm using:

MIN = apply(EWMA_SD252[,2:102]*100,1,min)

But I would like to take the minimum of each line but disregarding the values 0, any idea?

    
asked by anonymous 20.05.2014 / 22:26

1 answer

3

Instead of using min in apply , you can apply an anonymous function that selects the minimum only of nonzero numbers ( function(x) min(x[x!=0]) ). For example, in your code it would look like this:

MIN = apply(EWMA_SD252[,2:102]*100,1,function(x) min(x[x!=0]))
    
20.05.2014 / 23:56