简体   繁体   中英

How to interpolate zeros in a time series data in R

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM