Learn R Programming

eeptools (version 0.3.1)

mapmerge: Combine an S4 polygon object with a dataframe

Description

Convenience function for merging dataframes and S4 spatial polygon objects.

Usage

mapmerge(mapobj, data, xid, yid)

Arguments

mapobj
Name of an S4 SpatialPolygonsDataFrame
data
Name of an S3 dataframe
xid
Name of ID variable in the SpatialPolygonsDataFrame
yid
Name of ID variable in the S3 dataframe

Value

  • A SpatialPolygonsDataFrame with new variables attached from supplied dataframe

Examples

Run this code
xx <- maptools::readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], IDvar="FIPSNO")
yy<-as(xx,"data.frame")
yy$newvar<-sample(letters,nrow(yy),replace=TRUE)
yy<-subset(yy,select=c("FIPS","newvar"))
newpoly<-mapmerge(xx,yy,xid="FIPS",yid="FIPS")

Run the code above in your browser using DataLab