[R-sig-Geo] problem with adding data to spatialpolygonsdataframe
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Mon Nov 15 09:35:08 CET 2010
On 11/15/2010 09:26 AM, Franziska Schulze wrote:
> It works now. Am I sure that it puts my new variable as last column in
> my frame?
I think you can be sure.
> Is it possible to sort the spatial polygons data frame with
> respect to one variable?
my_spdf[order(my_spdf$my_column),]
>
>
> ----- Original Message ----- From: "Barry Rowlingson"
> <b.rowlingson at lancaster.ac.uk>
> To: "Franziska Schulze" <franziska.schulze at wiwi.hu-berlin.de>
> Cc: <r-sig-geo at stat.math.ethz.ch>
> Sent: Friday, November 12, 2010 4:28 PM
> Subject: Re: [R-sig-Geo] problem with adding data to
> spatialpolygonsdataframe
>
>
> On Fri, Nov 12, 2010 at 11:27 AM, Franziska Schulze
> <franziska.schulze at 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 at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics e.pebesma at wwu.de
More information about the R-sig-Geo
mailing list