Question

Could anyone help answer how to interpolate zeros in a time series data using linear interpolation? I know there is function to interpolate NA (missing values) in a time series data, is there something similar function to deal with zeros?

Was it helpful?

Solution

Try this. It also works with zoo and with ts series:

> library(zoo)
> x <- c(1, 0, 2) # sample data
> na.approx(replace(x, x == 0, NA))
[1] 1.0 1.5 2.0

Please provide sample data next time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top