r - if (antipodal(p1, p2)) { 中的错误:(R Geosphere Package)中需要 TRUE/FALSE 的缺失值
问题描述
我正在尝试使用他们积累的 openflights.com 数据将所有主要机场及其航线的地图可视化。我不断收到此错误:“if (antipodal(p1, p2)) { : 缺少 TRUE/FALSE 需要的值”在最后并且非常卡住!任何帮助,将不胜感激。
#Source is from openflights.com, had to manually import dataset on R.
colnames(routes)<-c("Airline","AirlineID","SourceAirport","SourceAirportID","Desination Airport","Desination AirportID","Codeshare","Stops","Equipment")
direct_flights<-routes[which(routes$Stops==0),]
direct_flights=na.omit(direct_flights)
colnames(airports)<-c("AirportID","Name","City","Country","IATA","ICAO","Latitude","Longitude","Alt","TImezone","DST","TZ database")
colnames(airports_all)<-c("AirportID","Name","City","Country","IATA","ICAO","Latitude","Longitude","Alt","TImezone","DST","TZ database")
tab<-table(direct_flights$SourceAirportID)
big.id <- names(tab)[tab>100] #Airports with more than 100 flights in and out
airport.index <- which(
unlist(lapply(airports$AirportID,function(x){
any(big.id==x)
}))
)
airports <- airports[airport.index,]
direct_flights.source.index <- which(
unlist(lapply(direct_flights$SourceAirportID,function(x){
any(big.id==x)
})))
direct_flights.target.index <- which(
unlist(lapply(direct_flights$`Desination AirportID`,function(x){
any(big.id==x)
}))
)
direct_flights <- direct_flights[intersect(direct_flights.source.index,direct_flights.target.index),]
library(geosphere)
library(maps)
plot_my_connection=function( dep_lon, dep_lat, arr_lon, arr_lat, ...){
inter <- gcIntermediate(c(dep_lon, dep_lat), c(arr_lon, arr_lat), n=10, addStartEnd=TRUE, breakAtDateLine=FALSE)
inter=data.frame(inter)
diff_of_lon=abs(dep_lon) + abs(arr_lon)
if(diff_of_lon > 180){
lines(subset(inter, lon>=0), ...)
lines(subset(inter, lon<0), ...)
}else{
lines(inter, ...)
}
}
for(i in 1:nrow(unique(direct_flights))){
node1 <- airports[airports$AirportID==direct_flights$SourceAirportID[i],]
node2 <- airports[airports$AirportID==direct_flights$`Desination AirportID`[i],]
map("world",col="white",fill=TRUE,bg="black",lwd=0.1,ylim = c(-90,90))
points(airports_all$Longitude,airports_all$Latitude,pch=19,col="blue",cex=0.2)
plot_my_connection(node1$Longitude[i], node1$Latitude[i],node2$Longitude[i],node2$Latitude[i],col="red")
}
我不断得到这个: if (antipodal(p1, p2)) { 中的错误:需要 TRUE/FALSE 的缺失值
不知道这意味着什么,已经尝试了几个小时!任何帮助,将不胜感激。
解决方案
推荐阅读
- java - 在 Spring Boot 中加载外部库的配置
- php - Delete id if not in database from a value
- javascript - 在 reactjs 中从 JSON 获取数组
- datatable - Eclipse 在使用 Cucumber 数据表时无法找到 raw() 方法
- sql - 用于查找具有某些值的记录的 SQL 查询在同一个表中具有不同的 id
- java - 当我将 javaFX stage 的 re-sizable 属性设置为 false 时,为什么我的内容周围会出现空白?
- arrays - Json-schema - 如何验证特定元素不在数组中?
- shuffle - 随机改组 Torch 张量
- api - 从 NVP 移植到 REST API
- python - 将excel文件中的所有excel表导入pandas