[R-sig-Geo] calculate geometric mean of mass of points
Ashton Shortridge
ashton at msu.edu
Wed Nov 19 21:04:02 CET 2008
On Wednesday 19 November 2008 02:33:46 pm Alessandro wrote:
> I have a points shape and I wish to calculate the geometric centre of this
> points shape and create a new points with R. But It's over my knowledge. Is
> there suggestions?
This seems straightforward, even if it is not implemented in a package.
Wikipedia has some basic info on the geometric mean:
http://en.wikipedia.org/wiki/Geometric_mean
All you seem to have to do is read the shapefile in, grab the x's and y's in
two vector (called, say, x and y) and then:
totalX <- 1
for(i in x) {totalX <- totalX * i}
totalY <- 1
for(i in y) {totalY <- totalY * i}
geomnX <- totalX^(1/length(x))
geomnY <- totalY^(1/length(y))
You could then make an sp object out of this pair and export it as a
shapefile, if you wished.
There is probably something slick you could do with lapply or something to
avoid the for loops in the code above, but I'm doing this off the top of my
head.
Also note that if any of your coordinate values are zero then the mean will be
zero and may not represent a centered value very well. Also note that
negative coordinate values are problematic. This solution assumes that all
your coordinates are positive.
Yours,
Ashton
On Wednesday 19 November 2008 02:33:46 pm Alessandro wrote:
> Hi all,
>
>
>
> I have a points shape and I wish to calculate the geometric centre of this
> points shape and create a new points with R. But It's over my knowledge. Is
> there suggestions?
>
>
>
> Thanks
>
>
>
> Ale
More information about the R-sig-Geo
mailing list