Displaying 1 result from an estimated 1 matches for "na_run".
Did you mean:
arun
2012 Aug 01
0
how to use function of rle approx ifelse etc. in data frame
...han 5 continuous NA, repeat the prior
data; if there are 5-10 NA, do a linear interpolation; and if there are more
than 10 NA, delete the whole month;
3, if the first day of the month is NA, use the function backward.
So far thanks to sebastian-c, the part of more than 10 NA is done:
library(zoo)
NA_run <- function(x, maxlen){
runs <- rle(is.na(x$value))
if(any(runs$lengths[runs$values] >= maxlen)) NULL else x
}
library(plyr)
rem <- ddply(M2, .(ID, year, month), NA_run, 10)
As to the other two parts, I figured out if less than 5 NA, use:
na.locf(rem$value, na.rm=FAL...