[R] Matrix elements
Christos Hatzis
christos at silicoinsights.com
Mon Mar 27 07:12:00 CEST 2006
To follow up on my previous posting, if you just need the row numbers try
this instead:
row(x)[apply(x, 1, FUN=function(x) ifelse(sum(x)>0 &
prod(x)>0,TRUE,FALSE)),1]
-Christos
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Akkineni,Vasundhara
Sent: Sunday, March 26, 2006 11:49 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Matrix elements
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