Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top