[R] Matrix elements

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Mar 27 08:50:28 CEST 2006


Gabor Grothendieck wrote:

> Try this:
> 
> which(xx[,1] > 0 & xx[,2] > 0)
> 


... or more generally for an arbitrary number of columns:

   which(apply(xx > 0, 1, all))

Uwe Ligges



> On 3/26/06, Akkineni,Vasundhara <vasu.akkineni at louisville.edu> wrote:
> 
>>Hello all,
>>
>>I have a matrix object, xx given as below:
>>
>>            [,1]         [,2]
>> [1,]  0.02237883  0.601572660
>> [2,] -0.39880918  0.126498958
>> [3,]  0.20269214  0.567953402
>> [4,] -0.45750812 -0.031193600
>> [5,] -0.30666134 -0.084819484
>> [6,] -0.37718928  0.078675868
>> [7,] -0.25432685 -0.005200316
>> [8,] -0.22146224  0.168196438
>> [9,] -0.32049919 -0.013216047
>>[10,]  0.94325749  1.341664313
>>
>>How can i check for every row in the matrix that both the column elements are greater than zero, and if they are greater than zero then to print the row number. I tried using for loops, but it kept returning warnings. Please let me know how this can be done.
>>
>>Thanks,
>>Vasu.
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>>
> 
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list