Skip to content
Back to formatted view

Raw Message

Message-ID: <200911211834.nALIYTG1006764@biglossa.ucdavis.edu>
Date: 2009-11-21T18:34:29Z
From: Jim Bouldin
Subject: consecutive numbering of elements in a matrix

Within a very large matrix composed of a mix of values and NAs, e.g, matrix A:

     [,1] [,2] [,3]
[1,]    1   NA   NA
[2,]    3   NA   NA
[3,]    3   10   17
[4,]    4   12   18
[5,]    6   16   19
[6,]    6   22   20
[7,]    5   11   NA

I need to be able to consecutively number, in new columns, the non-NA
values within each column (i.e. A[1,1] A[3,2] and A[3,3] would all be set
to one, and subsequent values in those columns would increase by one, until
the last non-NA value is reached, if any). 

Any ideas?
Thanks


Jim Bouldin, PhD
Research Ecologist
Department of Plant Sciences, UC Davis
Davis CA, 95616
530-554-1740