Skip to content
Prev 140744 / 398506 Next

Generating maps in R

Aleksandr Andreev <aleksandr.andreev <at> duke.edu> writes:
This was exactly why I emphasised care. One way to try to do this is 
to extract the FS data slot:

FSd <- as(FS, "data.frame")

and then merge() FSd and agg2, using - untried - something like:

FS1d <- merge(FSd, agg2, by="row.names", all=TRUE)

and check

str(FS1d)

for sanity, and possibly eyeball:

match(row.names(FS1d), sapply(slot(FS, "polygons"),
 function(x) slot(x, "ID")))

before moving on to:

FS1 <- SpatialPolygonsDataFrame(as(FS, "SpatialPolygons"), data=FSD1)

The alternative is to subset FS to remove the geometries for which there 
is no data, but using merge to insert NAs ought to work too.

Roger