Re: Question about Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg106568] Re: [mg106544] Question about Mathematica
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sat, 16 Jan 2010 06:13:59 -0500 (EST)
- Reply-to: hanlonr at cox.net
data = {
{{1, 2}, {3, -1}, {2, -4}},
{{1, 2}, {4, -5}, {6, -8}},
{{2, -1}, {-2, -3}, {-4, 6}}};
SortBy[#, Last][[1]] & /@ data
{{2, -4}, {6, -8}, {-2, -3}}
Cases[#, {_, Min[#[[All, -1]]]}][[1]] & /@ data
{{2, -4}, {6, -8}, {-2, -3}}
f[x_] := Select[x, #[[-1]] == Min[x[[All, -1]]] &]
First /@ f /@ data
{{2, -4}, {6, -8}, {-2, -3}}
Bob Hanlon
---- Dominic <miliotodc at rtconline.com> wrote:
=============
Hi. Can someone help me with the following question:
I have a table of a table of number pairs:
{{{1,2),(3,-1),{2,-4)},{{1,2},{4,-5},{6,-8}},{{2,-1},{-2,-3},{-4,6}}}
How may I find the minimum second element in each sub-table? For
example, the first sub-table is:
{{1,2},{3,-1},{2,-4}}
I would like to then extract the {2,-4} element from this item. Then
the {6,-8} from the second sub-table, then the {-2,-3} element from the
last.
Thank you,
Dominic