[R-sig-Geo] Spatialpolygonsdataframe

Metastate Metastate metastate at gmail.com
Wed Aug 19 02:57:53 CEST 2015


Hi

I tried to use sp merge to join the spatialpolygonddataframe (xx) and an
dataframe (yy4), which have 2 observations for each spatial ID. But it did
not allow with an error message as below:
 Error in .local(x, y, ...) :  'y' has multiple records for one or more
'by.y' key(s)

I also tried the mapmerge in eeptools but failed.

Any suggestion? Thank you very much.

Meta


library("eeptools")
library("sp")
xx <- maptools::readShapePoly(system.file("shapes/sids.shp",
package="maptools")[1], IDvar="FIPSNO")
yy<-as(xx,"data.frame")
yy$newvar<-sample(0:100,nrow(yy),replace=TRUE)
yy<-subset(yy,select=c("FIPS","newvar"))
yy3<-yy
yy3$newvar<-10*yy3$newvar
yy4<-data.frame(rbind(yy,yy3))
newpoly<-merge(xx,yy4,sort=FALSE, by.x="FIPS",
                  by.y="FIPS" ,all.y=TRUE)


On Tue, Aug 18, 2015 at 7:31 PM, Metastate Metastate <metastate at gmail.com>
wrote:

> Cool. Let me take a look. Thank you very much, Loïc.
>
> Meta
>
>
>
> On Tue, Aug 18, 2015 at 3:31 AM, Loïc Dutrieux <loic.dutrieux at wur.nl>
> wrote:
>
>> Hi,
>>
>> Have a look at merge in the sp package.
>> ?sp::merge
>>
>> Cheers,
>> Loïc
>>
>> On 08/18/2015 04:12 AM, Metastate Metastate wrote:
>>
>>> Hi all,
>>>
>>> I am starting to learn spatial analysis using R. Do anyone know if the
>>> attribute data in a spatialpolygonsdataframe can contain multiple
>>> observations within the same polygon? To be specific, I have a
>>> spatialpolygonsdataframe that contain USA county polygons and the
>>> relevant
>>> attribute data contains the relevant state,county and FIPs.  And I also
>>> have another data-frame that contains weather features by year by county
>>> (For example there are yearly average temperature for each county) . How
>>> can I join the spatialpolygondataframe with the weather data so that the
>>> resulted attribute table in the joint spatialpolygonsdataframe can
>>> contain
>>> *multiple-year* weather features within each county?
>>>
>>> Thank you very much for any kindly help.
>>>
>>> Meta
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list