In R I want to consolidate rows where data points with the same x,y coordinates can be merged with a formula to give a single row representing the combined area values. (Multi-stemmed trees but the same plant with representative combined diameter or cross-sectional area)) So in this simple example of a data frame:
{x <- c(6, 6, 6, 2, 2, 3, 4, 4, 7, 8)
y <- c(6, 6, 6, 4, 3, 7, 4, 6, 6, 10)
diam <- c(12, 9, 7, 16, 19, 4, 7, 8, 9, 3)
forest <- tibble(x,y, diam)
ggplot(data = forest) +
geom_point(mapping = aes(x = x, y = y, size = diam))
}
What I want to do is isolate the duplicate x,y rows and reduce it to a single row representing the combined diameters, something like the mean but a bit more complicated (I can fill that in later).
I have read and studied all the posts here about removing duplicates, but I don't want to do that; I want to consolidate them, leaving a single row with a representative diameter or circular area for combined stems of the same plant.