user2495069
user2495069

Reputation: 351

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?

Upvotes: 0

Views: 1293

Answers (1)

G. Grothendieck
G. Grothendieck

Reputation: 270020

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.

Upvotes: 2

Related Questions