I have a list of the form:
{{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}, {{9, 10}, {11, 12}}}
How can I create a function which will take each set at the highest level of the list:
{{1, 2}, {3, 4}}
{{5, 6}, {7, 8}}
{{9, 10}, {11, 12}}
And subtract the first element of the set from the second element of the set, here:
{3, 4} - {1, 2} = {2, 2}
{7, 8} - {5, 6} = {2, 2}
{11, 12} - {9, 10} = {2, 2}
Then compute the average or median of these values ({2, 2} here in either case)? It's clear how to do this using loops or tables, but is there a simpler way to proceed that makes clever use of Mathematica?
For a table based implementation:
PairList = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}, {{9, 10}, {11, 12}}};
PLMean = Mean[Table[PairList[[u, 2]] - PairList[[u, 1]], {u, 1, Length[PairList]}]]
Partwith the entire list:Mean[list[[All, 2]] - list[[All, 1]]]– Mike Honeychurch Jul 20 '13 at 08:03