Thanks to you both - I tried the latter and I havent understood it properly.
after doing

s$test <- test           (test is of class numeric)

I used writePolyShape(s$test, s) which returns an error saying that it is
not of class SpatialPolygonsDataFrame. I think I am missing a step here.

adv

On Mon, Mar 21, 2011 at 3:09 PM, Tom Gottfried <tom.gottfried@wzw.tum.de>wrote:

> you can even operate directly on the object you obtained from reading the
> shapefile. To add a column called test just do
>
> s$test <- test
>
> assuming that test has length(test)==nrow(s). In case you want it back in
> the shapefile use writePolyShape.
>
> Tom
>
> Am 21.03.2011 19:56, schrieb Johannes Signer:
>
>  You can access the data slot of a shapefile s by:
>>
>> d<- s@data
>>
>> d is data frame, where you can a column and write it back to the
>> shapefile.
>>
>> s@data<- d
>>
>> Hope this helps
>> Johannes
>>
>> On Mon, Mar 21, 2011 at 7:29 PM, Advait Godbole<advaitgodbole@gmail.com
>> >wrote:
>>
>>  Dear R-users,
>>>
>>> I am reading a shapefile in to R using readShapePoly, do some spatial
>>> modeling on it and obtain a new variable which I want to write to the
>>> same
>>> polygons as a new attribute (variable) preserving the spatial structure.
>>> Is
>>> there a straightforward way of doing it via a "write-to-shapefile"
>>> function?
>>>
>>> Thanks in advance,
>>>
>>> --
>>> advait godbole
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>>
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> --
> Technische Universität München
> Department für Pflanzenwissenschaften
> Lehrstuhl für Grünlandlehre
> Alte Akademie 12
> 85350 Freising / Germany
> Phone: ++49 (0)8161 715324
> Fax:   ++49 (0)8161 713243
> email: tom.gottfried@wzw.tum.de
> http://www.wzw.tum.de/gruenland
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
advait godbole

	[[alternative HTML version deleted]]

