ArmorCode ArmorCode - 7 days ago 5
R Question

Mean of 2-dimensional data points

I have these data points:

> a1 = c(2,10)
> a2 = c(2,5)
> a3 = c(8,4)


And I'd like to find the 2 dimensional mean (edit: Centroid) of those data points with r.

I have tried the following:

>mean(c(a1,a2,a3))


but it only gives me a one-dimensional mean value. How can I get the mean of the points?

Answer

If you have 3 points always-

centroid <- (a1 + a2 + a3) / 3
Comments