Dear Erin I use this one that I found on raymond florax's website for spatial econometrics. <br>It works great with points as well as with polygons. <br>PS: I will attach the R file if you need I can send you the files he used to you on another email. <br>
Hope it helps you <br>Juan Tomás <br># import your shapefile using readShapePoly<br>shape <- readShapePoly("columbus.shp",IDvar="POLYID")<br><br># read-in the table containing the data the you want to add to your shapefile<br>
# make sure that the table contains a column with a unique identifier corresponding to IDvar<br>tab <- read.table("join_example.txt",header=TRUE)<br><br># creates a vector of all polygon IDs<br> #note that it is the "character" version of POLYID (in this example)<br>
shpID <- sapply(slot(shape,"polygons"),function(x) slot(x,"ID"))<br><br># make the ID variable from the data table into class "character"<br>tabID <- as.character(tab$ID)<br><br># match the two unique identifiers<br>
# match() needs both its arguments to be of the same class. Here: "character"<br> <br> #### if you want to keep all polygons<br> tab <- tab[match(shpID,tabID),]<br> # matches both IDs and replaces nomatch values by NA<br>
rownames(tab) <- shpID<br> shape.mod <- spCbind(shape,tab)<br> <br> #### if you want to delete polygons with no matching data in the table<br> #tab <- tab[shpID%in%tabID,]<br> #shape.mod <- shape.mod[shpID%in%tabID,]<br>
# matches and removes the non-matching locations from the table and the original shapefile<br> #shape.mod <- spCbind(shape.mod,tab)<br><br><br><br><div class="gmail_quote">On Tue, Nov 1, 2011 at 2:33 AM, Hodgess, Erin <span dir="ltr"><<a href="mailto:HodgessE@uhd.edu">HodgessE@uhd.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Dear R Sig Geo People:<br>
<br>
Is there an equivalent of "join" from ArcGIS 10 in R, please?<br>
<br>
I've been experimenting with "match" but the results between the two are not the same.<br>
<br>
thanks,<br>
Sincerely,<br>
Erin<br>
<br>
<br>
Erin M. Hodgess, PhD<br>
Associate Professor<br>
Department of Computer and Mathematical Sciences<br>
University of Houston - Downtown<br>
mailto: <a href="mailto:hodgesse@uhd.edu">hodgesse@uhd.edu</a><br>
<br>
<br>
[[alternative HTML version deleted]]<br>
<br>
_______________________________________________<br>
R-sig-Geo mailing list<br>
<a href="mailto:R-sig-Geo@r-project.org">R-sig-Geo@r-project.org</a><br>
<a href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo" target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><font size="4">Juan Tomás Sayago Gómez<br>Graduate Research Assistant<br>West Virginia University<br><span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">886 Chestnut Ridge Road, Room 520<br>
P.O. Box 6825<br>Morgantown, WV 26506-6825</span></span></font><br><br>