更新时间:2022-03-22 23:45:22
您可以这样做
library(raster)
charafr <- c('RWA', 'BDI', 'UGA')
带有for循环:
ac <- list()
for (i in 1:length(charafr)){
ac[[i]] <- getData('GADM', country=charafr[i], level=0)
}
allac <- do.call("bind", ac)
plot(allac)
或者,通过 lapply
,更简洁,但可读性更差:
Or, with lapply
, more concise, but less readable:
charafr <- c('RWA', 'BDI', 'UGA')
allac2 <- do.call("bind", lapply(charafr, function(x) getData('GADM', country=x, level=0)))
要将其作为shapefile保存到磁盘,可以执行
To save this to disk as a shapefile, you can do
shapefile(allac2, 'allac.shp')