Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1996

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How do I use Select[list,condition]?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg4528] Re: How do I use Select[list,condition]?
  • From: Stephen P Luttrell <luttrell at signal.dra.hmg.gb>
  • Date: Wed, 7 Aug 1996 04:17:36 -0400
  • Organization: Defence Research Agency, Malvern
  • Sender: owner-wri-mathgroup at wolfram.com

Jason Welter wrote:
> 
> I have a list that looks like:
> 
> data = {{1,1,a,4,5,6},{2,1,a,2,3,4},{3,1,a,7,8,9},
>                {1,2,b,4,5,6},{2,2,b,2,3,4},{3,2,b,7,8,9},
>                {1,3,c,4,5,6},{2,3,c,2,3,4},{3,3,c,7,8,9}}
> 
> and I want to pick out the lists that have a 2 as the second element
> of the list.  I tried something like:
> 
> data1 = Select[data,data[[#,2]]==2];
> 
> but this doesn't work.  How do I do it?

Try the following:

data = {{1,1,a,4,5,6},{2,1,a,2,3,4},{3,1,a,7,8,9},
               {1,2,b,4,5,6},{2,2,b,2,3,4},{3,2,b,7,8,9},
               {1,3,c,4,5,6},{2,3,c,2,3,4},{3,3,c,7,8,9}};
Select[data, MatchQ[#, {_,2,___}]&]

which produces the output

{{1, 2, b, 4, 5, 6}, {2, 2, b, 2, 3, 4}, {3, 2, b, 7, 8, 9}}

-- 
Dr Stephen P Luttrell                  luttrell at signal.dra.hmg.gb
Adaptive Systems Theory                01684-894046 (phone)
Room EX21, Defence Research Agency     01684-894384 (fax)           
Malvern, Worcs, WR14 3PS, U.K.         http://www.dra.hmg.gb/cis5pip/Welcome.html

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Newby: filing graphics in MMA-WIN
  • Next by Date: Re: How do I use Select[list,condition]?
  • Previous by thread: Re: How do I use Select[list,condition]?
  • Next by thread: Re: How do I use Select[list,condition]?