Re: Request for help: working with multi-level lists
- To: mathgroup at smc.vnet.net
- Subject: [mg13684] Re: Request for help: working with multi-level lists
- From: "Allan Hayes" <hay at haystack.demon.cc.uk>
- Date: Sat, 15 Aug 1998 04:39:16 -0400
- References: <6qp3mc$al3@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
KCConnolly wrote in message <6qp3mc$al3 at smc.vnet.net>...
>I have a list of 10 elements, each of which is a list of three elements
>(let's say in each case an integer, a real number, and a string). I am
>looking for the most elegant way to select those first-level elements
>(i.e., the lists) whose integer element is equal to a particular value
>(let's say "1"), and then to obtain the mean of the real number
>elements of the lists selected. This seems as if it should be simple,
>but everything I try leads to Part specification errors. Any help
>would be greatly appreciated.
>
M[l_,k_]:=((Plus@@#)/Length[#])&[Cases[l, {k,r_,_}:>r]]
M[{{3,.3,"b"},{1,1,"c"},{3,.6,"d"}}, 3]
0.45
Allan
-------------------------------------------------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
http://www.haystack.demon.co.uk
hay at haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44(0)116 271 8642