Re: Request for help: working with multi-level lists
- To: mathgroup at smc.vnet.net
- Subject: [mg13670] Re: [mg13665] Request for help: working with multi-level lists
- From: wself at viking.emcmt.edu (Will Self)
- Date: Sat, 15 Aug 1998 04:39:04 -0400
- Sender: owner-wri-mathgroup at wolfram.com
>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.
mean[aList_]:= Plus@@aList/Length[aList]
mainList={{1, .1, "a"}, {1, .2, "b"}, {1, .3, "c"}, {1, .4, "d"}}
mean[ #[[2]]& /@ Select[mainList, #[[1]]==1&] ]
Will Self
Montana