[R] Index (which) of last non-NA data in dataframe

From: Pierre Lapointe <pierrelap_at_gmail.com>
Date: Tue 28 Jun 2005 - 11:24:17 EST


Hello,  

In a dataframe, I want the index if the last non-NA data. Example:  

d<-data.frame(matrix(c(1,3,4,2,7,8,1,NA,2),3,3,byrow=TRUE))  

gives:

> d

  X1 X2 X3

1 1 3 4

2 2 7 8

3 1 NA 2  

I want a vector that gives me 3 2 3  

I know about tail and which, but I don't know how not to consider the NA  

e.g.: last<-tail(d,1,na.rm=TRUE) still gives me a NA

> last

  X1 X2 X3

3 1 NA 2

        [[alternative HTML version deleted]]



R-help@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 Received on Tue Jun 28 11:29:01 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:03 EST