Re: Using Select within Map

• To: mathgroup at smc.vnet.net
• Subject: [mg71799] Re: Using Select within Map
• From: dh <dh at metrohm.ch>
• Date: Wed, 29 Nov 2006 02:56:49 -0500 (EST)
• Organization: hispeed.ch
• References: <ekh70s\$s7p\$1@smc.vnet.net>

```
Hi Mark,

Mathematica is clever enough to figure where an argument belongs if this

is possible. E.g.:

Map[2 # &, Select[{a, b, c, a}, (# == a || # == b) &]]

Of course, if you e.g. multiply arguments of different functions, there

is no way Mathematica could know which argument belongs to which function.

If the # notation does not work, there is still the notation:

Function[x,..] that works with named arguments.

Daniel

Mark Teagarden wrote:

> Hi,

>

> I have a data set which comprises several paired lists, like so (I apologize

> if the tabs do not come out correctly in your mail client):

>

> x =

> {

>     {

>         { , },

>         { , },

>         { , }

>     },

>     {

>         { , },

>         { , },

>         { , }

>     },

>     {

>         { , },

>         { , },

>         { , }

>     }

> }

>

> What I would like to do is to select from each of those paired lists, only

> those pairs where the first value in the pair falls within some specified

> range, and then obtain a mean.  This would be simple enough if I was

> operating on a single paired list, for example:

>

> Select[x[[1]],a < #[[1]] < b&]

>

> However, I would like to Map over x so that I would end up with means for

> each of the level 1 lists within x; therein lies the problem.  Both Map and

> Select use the Slot operator (#), and I don't know how to distinguish

> between the slot operator used by Map, and the slot operator used by Select:

>

> Select[#,a < #[[1]] < b&]/@x

>

> Or if you prefer:

>

> Map[Select[#, a < #[[1]] < b&,x]

>

> This problem has been plaguing me for some time, and if I could punch

> through it I would be very happy indeed.  Any ideas?  I have had no luck

> looking through the archives or the Help Browser.  On a similar note, I

> would eventually like to modify this solution so that the criteria, a and b,

> could vary with each level 1 list in x, but one thing at a time...

>