On Fri, Nov 12, 2010 at 11:27 AM, Franziska Schulze <franziska.schu...@wiwi.hu-berlin.de> wrote: > Dear all, > > I have a SpatialPolygonsDataFrame and I want to add data to the regions, i.e. > I want to assign to every region in my data a value of a certain variable. I > tried using spCbind, but after using this, the dimensions of my > SpatialPolygonsDataFrame changed. What went wrong? Do I have to create a > matrix with the region's IDs and the values of my variable?
You can for the most part treat it like a data frame. For example, using the spdf created in help("SpatialPolygonsDataFrame-class") > summary(ex_1.7) Object of class SpatialPolygonsDataFrame Coordinates: min max x 0.5 10.5 y 0.5 10.5 Is projected: NA proj4string : [NA] Data attributes: x y z Min. : 1.0 Min. : 1.0 Min. :1.702 1st Qu.: 3.0 1st Qu.: 3.0 1st Qu.:2.626 Median : 5.5 Median : 5.5 Median :3.123 Mean : 5.5 Mean : 5.5 Mean :3.127 3rd Qu.: 8.0 3rd Qu.: 8.0 3rd Qu.:3.614 Max. :10.0 Max. :10.0 Max. :4.600 > ex_1.7$FOO=99 > summary(ex_1.7) Object of class SpatialPolygonsDataFrame Coordinates: min max x 0.5 10.5 y 0.5 10.5 Is projected: NA proj4string : [NA] Data attributes: x y z FOO Min. : 1.0 Min. : 1.0 Min. :1.702 Min. :99 1st Qu.: 3.0 1st Qu.: 3.0 1st Qu.:2.626 1st Qu.:99 Median : 5.5 Median : 5.5 Median :3.123 Median :99 Mean : 5.5 Mean : 5.5 Mean :3.127 Mean :99 3rd Qu.: 8.0 3rd Qu.: 8.0 3rd Qu.:3.614 3rd Qu.:99 Max. :10.0 Max. :10.0 Max. :4.600 Max. :99 > The dimension will change because you are adding a new column - if the number of rows have changed then something is going wrong... Post some code? Barry _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo