[R-sig-Geo] substract two columns in a shapefile (but SAGA+R has an bug error)
Roger Bivand
Roger.Bivand at nhh.no
Tue Feb 24 10:50:58 CET 2009
On Tue, 24 Feb 2009, Alessandro wrote:
> Dear Researcher,
>
>
>
> I have a shapefile with two columns "a" and "b" and I wish to subtract a-b
> to obtain a new column of difference. I tried in SAGA + R with the module
> "Table calculator for shapes". This worked without an error, but it didn't
> save the results either. I suspect that this is a bug in the SAGA module.
>
>
>
> Is there an another code or packages (without GRASS+R) to do operation with
> shapefile?
Why not do it the simple way?
Either:
library(maptools)
my_SPDF <- readShapeSpatial("myfile.shp")
my_SPDF$ab <- my_SPDF$a - my_SPDF$b
writeSpatialShape(my_SPDF, "mynewfile")
or:
library(rgdal)
my_SPDF <- readOGR(".", "myfile")
my_SPDF$ab <- my_SPDF$a - my_SPDF$b
writeOGR(my_SPDF, ".", "mynewfile", driver="ESRI Shapefile")
Insert a summary(my_SPDF) to check that a and b are what you think, and
that ab has been created. It won't work if a and/or b are strings.
Roger
>
>
>
> Thanks
>
>
>
> Ale
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list