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

• To: mathgroup at smc.vnet.net
• Subject: [mg13675] Re: Request for help: working with multi-level lists
• From: Hans Staugaard <hans.staugaard at get2net.dk>
• Date: Sat, 15 Aug 1998 04:39:08 -0400
• Organization: Get2Net Internet Kunde
• References: <6qp3mc\$al3@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```KCConnolly skrev:
>
> 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.

this should do the job...

first i define some data (not 10, only 3)

In[1]:=
data={{1,3.14,"Monkey"},{2,2.71,"Donkey"},{1,5.32,"Junkie"}}
Out[1]=
{{1,3.14,"Monkey"},{2,2.71,"Donkey"},{1,5.32,"Junkie"}}

then i select the ones satisfying the criteria

In[2]:=
tmp=Select[data,(#[[1]]==1)&]
Out[2]=
{{1,3.14,"Monkey"},{1,5.32,"Junkie"}}

and then calculate the mean of the real's

In[3]:=
mean=Plus@@Transpose[tmp][[2]]/Length[tmp]
Out[3]=
4.23

```

• Prev by Date: Re: Request for help: working with multi-level lists
• Next by Date: Re: Request for help: working with multi-level lists
• Previous by thread: Re: Request for help: working with multi-level lists
• Next by thread: unwrapping ArcTan