I have a dataset, say:
data =
{{10, 8.04}, {8, 6.95}, {13, 7.58}, {9, 8.81}, {11, 8.33}, {14, 9.96},
{6, 7.24}, {4, 4.26}, {12, 10.84}, {7, 4.82}, {5, 5.68}}
and I want to subtract the mean from it, producing:
correcteddata = {{1, 0.539091}, {-1, -0.550909}, {4, 0.0790909}, {0, 1.30909}, {2, 0.829091}, {5, 2.45909}, {-3, -0.260909}, {-5, -3.24091}, {3, 3.33909}, {-2, -2.68091}, {-4, -1.82091}}
However, I'm looking to do this on a much larger data-set as efficiently as possible.
I've gone through several attempts:
This was very slow, but simple:
correcteddata = # - Mean[data] & /@ data
This was significantly faster, but involves adding another variable:
m = Mean[data];
correcteddata = # - m & /@ data
The fastest/best I've found so far is this:
correcteddata = Transpose[# - Mean /@ # &[Transpose[data]]]
But I'm wondering if there is something better.
subtract the mean from it, you wish to subtract the sample means from the data. – wolfies Jul 02 '17 at 08:26