Skip to content
Prev 57951 / 398498 Next

functions for special na handling?

Robert Sams wrote:

            
Hi Robert,
   Will the following do?

na.approx <- function(x) {
   na <- is.na(x)
   if(all(!na)) return(x)
   i <- seq(along = x)
   x[na] <- approx(i[!na], x[!na], i[na])$y
   x
}

 > x <- c(10,11.4,NA,12,9.7)
 > na.approx(x)
[1] 10.0 11.4 11.7 12.0  9.7


--sundar