Hi
probably not the best solution but

if(tail(is.na(x), n=1)) x[1 : (length(x) -
(tail(rle(is.na(x))$lengths, n=1)))] else x 

shall do what you want.

HTH
Petr


On 2 Mar 2006 at 9:29, Robert Lundqvist wrote:

Date sent:              Thu, 2 Mar 2006 09:29:49 +0100 (MET)
From:                   Robert Lundqvist <[EMAIL PROTECTED]>
To:                     R-help@stat.math.ethz.ch
Subject:                [R] Skip last NA's?
Send reply to:          [EMAIL PROTECTED]
        <mailto:[EMAIL PROTECTED]>
        <mailto:[EMAIL PROTECTED]>

> I wonder if anyone could help me find an expression for skipping the
> last missing values in a vector? The kind of material I have is
> something like
> 
> x<-c(23,12,NA,23,24,21,NA,NA,NA)
> 
> I would like to skip the last NA's, but not the ones in between other
> vallues. Any hints? (Why not do this by simply take x[1:6]? I have
> several vectors a couple of thousand observations long with varying
> numbers of NA's in the end. I'd prefer not to search through all of
> these one at a time.)
> 
> Robert
> 
> ______________________________________________
> 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

Petr Pikal
[EMAIL PROTECTED]

______________________________________________
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

Reply via email to