samedi 7 mars 2015

Adding indexed variables to a list

This is a pretty basic question, but I am a beginner to R.


I have a map of Mozambique, along with its administrative districts. The districts have the unique identifier "ID_1", which ranges from 1915 to 1923.


I want to create a list of polygons of each district, and here is my code thus far:



library(sp)
library(rgdal)
library(spgrass6)
library(maptools)



Moz1 <- readShapePoly("MOZ_adm1.shp")

dflist <- list()

#Create a Polygon for each province, label it by ID, and add to a list

for (i in min(Moz1$ID_1):max(Moz1$ID_1)){
nam <- paste("Polygon", i, sep="")
assign(nam, subset(Moz1, Moz1$ID_1==i))
dflist <- nam
}


However, when I print 'dflist', there is only one item in the list, "Polygon1923".


What am I doing wrong? Thanks so much!





Aucun commentaire:

Enregistrer un commentaire