I have a database with time data. I want to interpolate data for a specific time step.
Id Time humid humtemp prtemp press t 1 2012-01-21 18:41:50 47.7 14.12 13.870 1005.70 -0.05277778 1 2012-01-21 18:46:43 44.5 15.37 15.100 1005.20 0.02861111 1 2012-01-21 18:51:35 43.2 15.88 15.576 1005.10 0.10972222 1 2012-01-21 18:56:28 42.5 16.17 15.833 1004.90 0.19111111 1 2012-01-21 19:01:21 42.2 16.31 15.986 1004.80 0.27250000 1 2012-01-21 19:06:14 41.8 16.47 16.118 1004.60 0.35388889 1 2012-01-21 19:11:07 41.6 16.51 16.177 1004.60 0.43527778
I want to get the data in steps below by doing interpolation.
Id Time humid humtemp prtemp press t 1 2012-01-21 18:45:00 .... ... ..... .... .... 1 2012-01-21 18:50:00 .... 1 2012-01-21 18:55:00 .... 1 2012-01-21 19:00:00 .... 1 2012-01-21 19:05:00 .... 1 2012-01-21 19:10:00 ....
I tried using different methods, but I did not find a solution. For example, I create a zoo object.
z <- zoo(MTS01m,order.by=MTS01m$Time) tstart2<-asP("2012-01-21 18:45:00") Ts<-1*60 y <- merge(z, zoo(order.by=seq(tstart2, end(z), by=Ts))) xa <- na.approx(y) xs <- na.spline(y)
but an error occurs:
Errore in approx(x[!na], y[!na], xout, ...) : need at least two non-NA values to interpolate Inoltre: Warning message: In xy.coords(x, y) : si รจ prodotto un NA per coercizione
I create a secundary index t that starts where I want to have data, but I don't know how to use the thid index.
Do you have any suggestions?
Marco giuliani
source share