Re: [R] indices of rows containing one or more elements >0

2008-02-12 Thread Berwin A Turlach
G'day Stanley, On Wed, 13 Feb 2008 10:40:09 +0800 "Ng Stanley" <[EMAIL PROTECTED]> wrote: > Hi, > > Given test <- matrix(c(0,2,0,1,3,5), 3,2) > > > test[test>0] > [1] 2 1 3 5 > > These are values >0 > > > which(test>0) > [1] 2 4 5 6 > > These are array indices of those values >0 > > > which

Re: [R] indices of rows containing one or more elements >0

2008-02-12 Thread jim holtman
Is this what you are after? > test <- matrix(c(0,2,0,1,3,5), 3,2) > (x <- which(test > 0, arr.ind=TRUE)) row col [1,] 2 1 [2,] 1 2 [3,] 2 2 [4,] 3 2 > unique(x[, 'row']) [1] 2 1 3 > On Feb 12, 2008 9:40 PM, Ng Stanley <[EMAIL PROTECTED]> wrote: > Hi, > > Given test <- matrix

Re: [R] indices of rows containing one or more elements >0

2008-02-12 Thread Henrik Bengtsson
X <- matrix(c(0,2,0,1,0,0,3,5), ncol=2) Informative version: isPositive <- (X > 0) nbrOfPositives <- apply(isPositive, MARGIN=1, FUN=sum) hasPositives <- (nbrOfPositives >= 1) positiveRows <- which(hasPositives) Compact version: positiveRows <- which(rowSums(X > 0) >= 1) If you have an extremely

[R] indices of rows containing one or more elements >0

2008-02-12 Thread Ng Stanley
Hi, Given test <- matrix(c(0,2,0,1,3,5), 3,2) > test[test>0] [1] 2 1 3 5 These are values >0 > which(test>0) [1] 2 4 5 6 These are array indices of those values >0 > which(apply(test>0, 1, all)) [1] 2 This gives the row whose elements are all >0 I can't seem to get indices of rows containin