简体   繁体   English

填写R中缺少的GPS值

[英]Filling in Missing GPS Values in R

I am looking at data from a device that spends much of its time underwater. 我正在查看一个花费大部分时间在水下的设备的数据。 When it surfaces, it gets a GPS fix (lat & lon) and then sinks (losing its GPS fix) and continues gathering data again until its next surfacing. 当它出现时,它会获得GPS定位(lat&lon)然后下沉(失去其GPS定位)并继续收集数据,直到下一次出现。 This results in a lot of NA values in the data for the lat lon values and they don't coincide with the underwater data readings. 这导致lat lon值的数据中存在大量NA值,并且它们与水下数据读数不一致。

I'd like to create a curtain plot of the data but I'll need some interpolated lat/lon values to do a rough plot of the subsurface data against for a 3D map. 我想创建数据的幕布图,但是我需要一些插值的lat / lon值来对3D图进行地下数据的粗略绘图。

How can I fill in some linearly interpolated values for the many NA's that occur in between GPS fixes in R? 如何填写R中GPS定位之间出现的多个NA的线性插值? They are in numeric DD.DDDDD format. 它们采用数字DD.DDDDD格式。

An example of the data can be found at: http://modata.ceoe.udel.edu/public/gps_example_data.csv 有关数据的示例,请访问: http//modata.ceoe.udel.edu/public/gps_example_data.csv

na.approx() in the zoo package does just what you're looking for. zoo包中的na.approx()您的需求。

With your data, do something like: 使用您的数据,执行以下操作:

df <- read.csv("http://modata.ceoe.udel.edu/public/gps_example_data.csv", 
               header=T)

library(zoo)

df2 <- 
transform(df, 
    m_gps_lat_dec = na.approx(m_gps_lat_dec, m_present_time, na.rm=FALSE),
    m_gps_lon_dec = na.approx(m_gps_lon_dec, m_present_time, na.rm=FALSE))

See also this StackOverflow post , which includes a nice worked example (and some useful comments from an author of the zoo package, to boot.) 另请参阅此StackOverflow帖子 ,其中包含一个很好的工作示例(以及来自zoo包的作者的一些有用的注释)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM