Question

I have two time series (sensor data) with different temporal resolutions. A time series from the class "xts / zoo" (TS1) includes hourly values and the other time series (TS2) has a better temporal resolution (one observation every 10 minutes). I.e. for TS1 I have 24 data points (observations) per day and for TS2 I have 144 data points per day.

When I calculate TS1-TS2 for one day I get a result with 24 data points (low temporal resolution). What I would like to achieve is to obtain a result with 144 data points (as TS2, better temporal resolution).

Is it possible to achieve this in R?

P.S.:

That's no a trivial problem because in an hourly interval I just have one observation from TS1 and 6 observations from TS2, so I could imagine this problem can be solved if one draws a fit line between every two points of TS1 and calculate the difference between the line and the data points from TS2. But I know no R Function to do this.

Was it helpful?

Solution

You can approximate missing values using na.approx for linear/constant approx or na.spline for polynomial one.

## new index to be used 
new.index <- 
  seq(min(index(TS1)),max(index(TS1)), by=as.difftime(10,units='mins'))
## linear approx
TS1.new  <- na.approx(merge(TS1 ,xts(NULL,new.index)))

Now you can susbtract your ts, (even if maybe you should check that they have same start dates)

TS2-TS1.new 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top