I am trying to take the mean of select values in a matrix column, selecting them by their value in a different column.
For example:
X=[1950 1;
1950 2;
1950 3;
1951 1;
1951 5;
1952 1]
I want to take the mean of the values per each year - essentially, select values with the same column 1 value, and then take the mean of the corresponding column 2 values. So the mean value for 1950
would be 2
, the mean value for 1951
would be 1
. I can do this manually by creating a vector for each year value and then taking the mean of the whole vector, but this is impractical for greater amounts of data. The number of data points for each year varies, so I don't think I can use reshape to do this.