从R

时间:2017-02-18 19:54:39

标签: r

我有一个坐标表,我需要使用R列出相应的城市。任何建议???

我试过了:

library(maps)

cities <- dataet
cities[is.na(cities)] <- 0
map.where("world", dataset$lon, dataset$lat, fill==TRUE)

1 个答案:

答案 0 :(得分:3)

以下是ggmap中反向地理编码的快速解决方案:

library(ggmap)

> coords
        lon      lat
1  37.61730 55.75583
2 116.40739 39.90421
3 -77.03687 38.90719

res <- lapply(with(coords, paste(lat, lon, sep = ",")), geocode, output = "more")


> transform(coords, city = sapply(res, "[[", "locality"))
        lon      lat       city
1  37.61730 55.75583     Moskva
2 116.40739 39.90421    Beijing
3 -77.03687 38.90719 Washington