Hi everybody, I have a little problem about filling some gaps of NAs in my data.
These gaps are between nearly constant data (temperature under snow). Here's a fake example to illustrate how it looks like approximately: DF <- data.frame(data=c(-0.51,-0.51,-0.48,-0.6,-0.54,-0.38,-0.6,-0.42,NA,NA,NA,NA,NA,NA,NA, -0.25,-0.41,-0.5,-0.5,-0.35,-0.7,-1,-0.87)) I would like to replace my NAs with "0" with this condition: Fill the gap with "0" if the mean of the 5 previous values before the gap (NA) is under 0°C, AND if the mean of the 5 following values after the gap (NA) is also under 0°C (actually it's not the 5 previous and following values in my real data, it's my 500 previous and following values, but let's juste take the 5 ones in my example). I think that the nearest function for doing this is the "na.locf" function of the package zoo, but it does not really do what I want. Can somebody help me to resolve this? Thanks a lot guys! -- View this message in context: http://r.789695.n4.nabble.com/filling-NA-gaps-according-to-previous-data-mean-and-following-data-mean-tp4646613.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.