Re: Selecting Many Things Rather Than Selecting One Thing From Many

• To: mathgroup at smc.vnet.net
• Subject: [mg66195] Re: Selecting Many Things Rather Than Selecting One Thing From Many
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Thu, 4 May 2006 05:19:34 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <e39k7e\$cno\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Gregory Lypny wrote:
> Hello everyone,
>
> I've discovered another use or need for the Select function, which I
> suspect requires mapping of some sort.
>
> In my previous posts, members of this MathGroup kindly showed me how
> to apply Select to many columns of a matrix at once.  For example,
>
> (Select[#1, #1 > K & ] & ) /@ Transpose[theMatrix]
>
> will pull out all values greater than K, where K is a number such as
> 100.
>
> But suppose now that K is a list of numbers, such as K={34, 876,
> 199}, and I simply want to extract or identify all of the rows in the
> first column of theMatrix equal to any one of those numbers.  How
> would I do that?  I started with
>
> Select[theMatrix, #[[1]]==any element of list K]
>
> and I imagine something similar could be applied to the Position
> function.
>
> Any hint would be much appreciated.
>
> 	Gregory
>
Hi Gregory,

I think the following expressions will direct you toward what you want:

In[1]:=
lst={{109,168,173,109},{4,143,200,90},{181,162,85,196},{30,
108,86,34},{94,127,144,34},{199,109,195,188},{176,
34,46,110},{95,27,160,109},{43,
71,130,66},{56,148,109,163},{110,43,50,53},{32,34,16,95}};

In[2]:=
TableForm[lst]

Out[2]//TableForm=
109   168   173   109

4     143   200   90

181   162   85    196

30    108   86    34

94    127   144   34

199   109   195   188

176   34    46    110

95    27    160   109

43    71    130   66

56    148   109   163

110   43    50    53

32    34    16    95

In[3]:=
K=100;
Select[lst,#1[[1]]>K&]//TableForm

Out[4]//TableForm=
109   168   173   109

181   162   85    196

199   109   195   188

176   34    46    110

110   43    50    53

In[5]:=
K={43,876,199};
Select[lst,MemberQ[K,#1[[1]]]&]//TableForm

Out[6]//TableForm=
199   109   195   188

43    71    130   66

In[7]:=
Position[lst[[All,1]],Alternatives@@K]//TableForm

Out[7]//TableForm=
6

9

In[8]:=
Position[lst,{x_,___}/;MemberQ[K,x]]//TableForm

Out[8]//TableForm=
6

9

Best regards,
Jean-Marc

```

• Prev by Date: Re: Faster Random Walk Simulation ?!?
• Next by Date: Re: Beginner--Help on using FindRoot to solve the system of equations
• Previous by thread: Re: Selecting Many Things Rather Than Selecting One Thing From Many
• Next by thread: Re: Selecting Many Things Rather Than Selecting One Thing From Many