0

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?

ArmorCode
  • 739
  • 4
  • 15
  • 33
  • 3
    Sequentially name variables are terrible and ungeneralizable. You should put your coordinates in a data frame or a matrix, with one column for the first coordinate and one column for the second coordinate. Then `colMeans(your_dat)` will do what you want. – Gregor Thomas Nov 29 '16 at 01:37
  • 3
    colMeans(rbind(a1,a2,a3)) – Ryan Nov 29 '16 at 02:11
  • Can you define "2 dimensional mean" more precisely? You are not, perhaps, thinking of the centroid ("centre of mass" of the points) ? – neilfws Nov 29 '16 at 02:38
  • @neilfws I'm referring to the centroid. I didn't know it was called that. I'll update the question to reflect that. – ArmorCode Nov 29 '16 at 03:03

1 Answers1

1

If you have 3 points always-

centroid <- (a1 + a2 + a3) / 3
code_is_entropy
  • 611
  • 3
  • 11