Re: [R] Generating maps in R

From: Roger Bivand <>
Date: Mon, 31 Mar 2008 12:25:57 +0000 (UTC)

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

> Roger Bivand Roger.Bivand at 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


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.


> 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
> mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 31 Mar 2008 - 12:40:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 31 Mar 2008 - 13:30:26 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive