Re: [R] Generating maps in R

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

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
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive