Pierre Roudier pierre.roudier at gmail.com
Tue Jan 11 23:34:32 CET 2011

Hi Gema,

I understand you have a polygon layer, stored as a shapefile. That
layer would store the districts within a given city. On the other
hand, you have informations about those districts.

If what you want is to merge those informations into your polygon
(spatial) layer, here's an example:


# I'm taking a polygon layer from the rgdal package to produce a
reproducible example
dsn <- system.file("vectors", package = "rgdal")[1]
sc <- readOGR(dsn=dsn, layer="scot_BNG")

# The data about your polygons is store in the "data" slot of the sc object:
summary(sc at data)

# Create some dummy properties you want to include. It may come from a CSV file.
# this include a key (id) to relate that data frame with the polygons.
dummy <- data.frame(id=rownames(sc at data),

# here I chose rownames(sc at data) as the key. You need to add the same
id column that to your sc at data
sc at data$id <- rownames(sc at data)

# Merge the informations into your sc at data data frame:
sc at data <- merge(sc at data, dummy, by="id")

# You're done:
spplot(sc, "property1")
spplot(sc, "property2")

In that example, I took the long way, there's probably some shortcuts
possible, but I thought that'd be easier to understand.



2011/1/12 GEMA FERNANDEZ-AVILES CALDERON <Gema.FAviles at uclm.es>:
> Dear all,
> first Happy 2011!
> I have two diferent files:
> - on the one hand a shapefile ( *.dbf, *,shp, *.shx) for a city and,
> -on the other hand different variables (*.csv or *.txt) for each district.
> I would like to joint the district with its variables for study its characteristics but I can't found how to merge the files.
> Could you help me?
> Thanks in advance,
> Gema
> Gema Fernández-Avilés
> Department of Statistics
> Faculty of Law and Social Sciences
> University of Castilla-La Mancha at Toledo
> http://www.uclm.es/profesorado/gemafaviles/t <http://www.uclm.es/profesorado/gemafaviles/t>
>        [[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

Landcare Research, New Zealand

More information about the R-sig-Geo mailing list