I have a simple map and like to export the used coordinates of latitude/longitude into an external CSV file. Is this possible?
library('maps')
map(database='world',regions='germany')
rcs
3,8941 gold badge30 silver badges31 bronze badges
1 Answer 1
The (invisible) return value of map
is a list with x
, y
, range
, and names
components (See Value section in the manual page, i.e. ?map
):
dat <- map(database="world",regions = "germany", plot = FALSE)
str(dat)
# List of 4
# $ x : num [1:596] 14.2 14.2 14 13.9 13.9 ...
# $ y : num [1:596] 53.9 53.9 53.9 53.9 53.9 ...
# $ range: num [1:4] 5.86 15.02 47.28 55.06
# $ names: chr [1:7] "Germany:Usedom" "Germany:Fehmarn" "Germany:Rugen" "Germany:4" ...
# - attr(*, "class")= chr "map"
write.table(data.frame(x = dat$x, y = dat$y), "germany.csv")
answered May 16, 2020 at 11:06
lang-r