[R] Extracting a row number from a matrix

Kartik Pappu kartik.pappu at gmail.com
Tue Aug 1 16:03:52 CEST 2006


Hi all,

I have a matrix with each column containing a large number of integers
(0 and above). in each column beyond a certain row (say row 120 in
column 1, row 134 in column 2, 142 in column 3...)  there are only
0's.  I want to find, for each column the row number of the last row
which contains a positive integer beyond which there are 10 or more
0's.

so in the following example (single column, but my real data has
multiple columns) how do I  get the row number of the last row of x
beyond which there are 10 or more 0's (which in this case is row#100).

x <- as.matrix(c(rep(seq(1:20),5),rep(0,20)))

I am still new to R so I was wondering if anyone had a quick fix.

Thanks
Kartik



More information about the R-help mailing list