[R] Generating maps in R

Roger Bivand Roger.Bivand at nhh.no
Mon Mar 31 14:25:57 CEST 2008


Aleksandr Andreev <aleksandr.andreev <at> duke.edu> writes:

> 
> Roger Bivand Roger.Bivand at nhh.no writes:
> 
> > Merge using:
> > FS1 <- spCbind(FS, agg2)
> 
> This call fails, because:
> Error in spCbind(FS, agg2) : different numbers of rows

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

> 
> The reason is because I have data in a001ter for 79 Federal Subjects,
> but russia.shp contains 193 labeled objects (93 Federal Subjects plus
> 100 Arctic Ocean Islands and other things). Is there a way I can merge
> without an equal number of rows, labeling the data for the Arctic
> islands as missing?
> 
> Thanks,
> 
> Aleks Andreev
> Duke University
>



More information about the R-help mailing list