Interpolate coordinates at unrecorded timestamps

不打扰是莪最后的温柔 提交于 2019-12-03 16:45:40

Since your data is a time series, you're better off using na.approx(...) in package zoo.

df$date.time <- with(df,as.POSIXct(paste(date,time),format="%m/%d/%Y %H:%M:%S"))
full.time    <- with(df,seq(date.time[1],tail(date.time,1),by=1))
library(zoo)
df.zoo <- zoo(df[,3:4],df$date.time)        # convert to zoo object
result <- na.approx(df.zoo,xout=full.time)  # interpolate; result is also a zoo object
head(result)
                         X        Y
2014-04-06 09:32:00 325695 672878.0
2014-04-06 09:32:01 325695 672876.2
2014-04-06 09:32:02 325695 672874.5
2014-04-06 09:32:03 325695 672872.8
2014-04-06 09:32:04 325695 672871.0
2014-04-06 09:32:05 325695 672869.2

There is also an na.spline(...) function if you need continuous derivatives at the grid points.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!