Interpolating timeseries

后端 未结 2 642
醉话见心
醉话见心 2020-12-01 09:42

I have a time series problem which I hope someone can help with!

The problem revolves around two sets of data with different time stamps. One set of data contains ca

2条回答
  •  醉酒成梦
    2020-12-01 10:18

    You can also use approx function like this and it will be much easier. Just make sure that you are working with data frames. Also, make sure that format of the column in calibration and sample data-set are the same by using as.POSIXct.

     calib <- data.frame(calib); sample <- data.frame(sample)
    
     IPcal <- data.frame(approx(calib$time,calib$value, xout = sample$time, 
                     rule = 2, method = "linear", ties = mean))
    
     head(IPcal)
    
    #                x        y
    #1 2017-03-22 01:00:52 252.3000
    #2 2017-03-22 01:03:02 251.1142
    #3 2017-03-22 01:05:23 249.9617
    #4 2017-03-22 01:07:42 252.7707
    #5 2017-03-22 01:10:12 255.6000
    

    Read more about approx on approxfun documentation.

提交回复
热议问题