【发布时间】:2018-03-31 01:16:40
【问题描述】:
我正在查看此链接中的示例代码。
http://www.milanor.net/blog/maps-in-r-plotting-data-points-on-a-map/
似乎数据集位置发生了变化,所以我稍微更改了代码以适应。
airports <- read.delim("https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat", sep=",")
colnames(airports) <- c("ID", "name", "city", "country", "IATA_FAA", "ICAO", "lat", "lon", "altitude", "timezone", "DST")
head(airports)
library(rworldmap)
newmap <- getMap(resolution = "low")
plot(newmap, xlim = c(-20, 59), ylim = c(35, 71), asp = 1)
points(airports$lon, airports$lat, col = "red", cex = .6)
routes <- read.csv("https://raw.githubusercontent.com/jpatokal/openflights/master/data/routes.dat", header=F)
colnames(routes) <- c("airline", "airlineID", "sourceAirport", "sourceAirportID", "destinationAirport", "destinationAirportID", "codeshare", "stops", "equipment")
head(routes)
library(plyr)
departures <- ddply(routes, .(sourceAirportID), "nrow")
names(departures)[2] <- "flights"
arrivals <- ddply(routes, .(destinationAirportID), "nrow")
names(arrivals)[2] <- "flights"
这一切看起来都很好。下面的代码似乎关闭了,但我不知道为什么。
airportD <- merge(airports, departures, by.x = "ID", by.y = "sourceAirportID")
airportA <- merge(airports, arrivals, by.x = "ID", by.y = "destinationAirportID")
我收到此错误:
警告信息: 在 merge.data.frame(机场,出发,by.x = "ID", by.y = "sourceAirportID") : 列名 ‘NA’, ‘NA’ 是 在结果中重复
警告信息: 在 merge.data.frame(airports,arrivals, by.x = "ID", by.y = "destinationAirportID") : 列名‘NA’、‘NA’在 结果
我做错了什么?
【问题讨论】:
标签: r