Re: Using Select within Map
- To: mathgroup at smc.vnet.net
- Subject: [mg71794] Re: Using Select within Map
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Wed, 29 Nov 2006 02:56:36 -0500 (EST)
- Organization: Uni Leipzig
- References: <ekh70s$s7p$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
Hi, a) the parser will parse if correct as to see from Hold[Map[Select[#, a < #[[1]] < b &], x]] // FullForm b) if you use Map[Select[#, Function[{q},a < q[[1]] < b],x] you will not mix up the two Slot[]s Regards Jens 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... > > Thanks in advance, > Mark >