I have a time series (wave height data) for which I need to fill in the blanks through interpolation. I found the na.approx
function in the zoo
package to do this, but I haven't found a way to make it take into account when the missing observation is much closer to one observation that the other.
Example:
library(zoo)
test = data.frame(Wave_Height = c(1.2, NA, 0.5), Data =
as.POSIXct(c("2019-01-01 00:00", "2019-01-01 05:00", "2019-01-01 06:00"),
format = "%Y-%m-%d %H:%M"))
> test
Wave_Height Data
1 1.2 2019-01-01 00:00:00
2 NA 2019-01-01 05:00:00
3 0.5 2019-01-01 06:00:00
test$Wave_Height = na.approx(test$Wave_Height)
> test
Wave_Height Data
1 1.20 2019-01-01 00:00:00
2 0.85 2019-01-01 05:00:00
3 0.50 2019-01-01 06:00:00
I feel like there should be a weight parameter somewhere, but scanning though the documentation I haven't been able to find it. I'm looking for a result like this:
> test
Wave_Height Data
1 1.20 2019-01-01 00:00:00
2 0.62 2019-01-01 05:00:00
3 0.50 2019-01-01 06:00:00