On Sat, Sep 11, 2010 at 4:26 PM, Waichler, Scott R <scott.waich...@pnl.gov> wrote: >> > Is there an existing function to compute the coordinates for the center >> > of mass of a variable in a 2D or 3D grid, where dx, dy, and dz are known >> > for all cells? The mass in each cell varies by location. >> >> If your data is in a data frame of coordinates x, y, (and maybe z), >> and variable W for all cells, and all your cells are the same size, >> then its just the weighted average of the coordinate (assuming your >> dataframe is the complete grid). So: >> >> xm = sum(d$x*d$W)/sum(d$W) >> ym = sum(d$y*d$W)/sum(d$W) > > You're right, it's simple for a grid where dx and dy are constant. Thanks. > But if they vary?
Treat the masses as points centred at each grid cell and then find the weighted mean of X and Y as before. I've just discovered there's a 'weighted.mean' function... Barry _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo