[R] Matrix elements

Liaw, Andy andy_liaw at merck.com
Mon Mar 27 07:00:31 CEST 2006


Something like this should work:

which(rowSums(xx > 0) == ncol(xx))

Andy

From: Akkineni,Vasundhara
> 
> 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
> 
>




More information about the R-help mailing list