Try this: aggregate(dt$value, list(long = dt$long, lat = dt$lat), FUN = sum)
On Mon, Jan 12, 2009 at 1:52 PM, Steve Murray <smurray...@hotmail.com>wrote: > > Dear all, > > > > I have a dataframe of 3 columns, consisting of 'longitude', 'latitude' > and a corresponding 'value'. Where identical 'longitude' and 'latitude' > pairs occur more than once, I want their corresponding 'value' to be > summed and the 'pair' to only appear once. > > > > For example: > > > > long lat value > > 10 20 5 > > 6 2 3 > > 27 -3 9 > > 10 20 10 > > 4 -1 0 > > 6 2 9 > > > > > > would be converted to something like: > > > > long lat value > > > 10 20 15 > > > 6 2 12 > > > 27 -3 9 > > > 4 -1 0 > > > > > > > ...as rows 1 and 4, 2 and 6 respectively are matched with respect to > the 'long' and 'lat' columns. Their values in column 3 are then summed > and reported as one row in the new dataframe. > > > > How would I go about coding this in R? > > > > Many thanks, > > > > Steve > > > _________________________________________________________________ > Are you a PC? Upload your PC story and show the world > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.