Re: Request for help: working with multi-level lists

*To*: mathgroup at smc.vnet.net*Subject*: [mg13673] Re: [mg13665] Request for help: working with multi-level lists*From*: "Carl K.Woll" <carlw at fermi.phys.washington.edu>*Date*: Sat, 15 Aug 1998 04:39:06 -0400*Organization*: Department of Physics*References*: <199808110856.EAA10664@smc.vnet.net.>*Sender*: owner-wri-mathgroup at wolfram.com

Hi, The way that I would do this is to use Cases, as in: realList = Cases[ li, {1, r_, _}->r ] to get a list of the numbers, where li is your list, and then to get the mean use mean = (Plus@@realList)/Length[realList] You could turn the above into a function, as in Mean[li_List] := (Plus@@li)/Length[li] Kmean[li_, i_Integer] := Mean[ Cases[li, {i, r_, _}->r] ] Carl Woll Dept of Physics U of Washington KCConnolly wrote: > 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.

**References**:**Request for help: working with multi-level lists***From:*kcconnolly@aol.com (KCConnolly)