我正在查看此链接中的示例代码。
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中(机场、起飞,In .x= "ID",in .y= "sourceAirportID"):列名‘NA’,‘NA’在结果中重复 警告信息:在merge.data.frame(机场,到达者,In .x= "ID",in .y= "destinationAirportID"):列名‘NA’,‘NA’在结果中重复
我做错了什么?
发布于 2018-03-30 17:16:40
首先,这些只是警告,而不是错误。也就是说,一切仍然正常,但可能不是预期的那样。这个问题产生于
colnames(airports) <- c("ID", "name", "city", "country", "IATA_FAA", "ICAO", "lat", "lon", "altitude", "timezone", "DST")其中只指定11个列名,而有14个列。因此,有三列被命名为NA,这对于merge来说是一个潜在的问题。
如果结果(即airportD和airportA)是预期的,则不需要更改任何内容。不过,最好给这三列取适当的列名。
https://stackoverflow.com/questions/49578342
复制相似问题