문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top