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

MathGroup Archive 2007

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

Search the Archive

Re: Using Select

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76248] Re: Using Select
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Fri, 18 May 2007 06:19:40 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <f2h94p$12p$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de

Hi,

try MatchQ[#[[3]],Blue] if you wist to select Blue
and MatchQ[#[[3]],_] as the wildcard. And
to make it more easy

mypattern={_,_,_,_,_};
...
If[characterSelectedQ,mypattern[[2]]=selectedCharacter];
If[colorSelectedQ,mypattern[[3]]=selectedColor];
...
Select[lst,MatchQ[#,mypattern] &]

will do the job in one step without to many And[]s

Regards
   Jens

Mark Coleman wrote:
> Greetings,
> 
> I'm working on a small application and I'm searching for a way to  
> Select a subset of rows from a list based upon a list of criteria  
> chosen by the user.  Here is small (hypothetical) example. Say one  
> has a data set of consisting of a list of as follows:
> 
> { {1,A,Blue,"Hello",10.5},{7,D,Green,"Goodbye",9.4}, 
> {6,S,Yellow,"Hello",6.9},{3,A,Blue,"Hello",8.0}....}
> 
> The user will specify a letter and a color and the program should  
> Select[ ] the appropriate rows, e.g., if I pick Color=Blue and Letter  
> = A, then it will return
> 
> { {1,A,Blue,"Hello",10.5},{3,A,Blue,"Hello",8.0}....}, etc.  Thus one  
> can enter Select[myData,(#[[2]]==A && #[[3]]==Blue)&] and get the  
> appropriate records.Note that The actual data set has about 20,000  
> records (lists), each with about 20 fields, and can select 7 or 8  
> different attributes, so the Select statements get fairly long.
> 
> My question involves an efficient way to code the Select statement if  
> a user wants to chose records that correspond to any value of a  
> particular field, e.g., All of the Color=Blue, regardless of the  
> Letter choice,e.g.,
> 
> Select[myData,(#[[3]]==Blue)&]
> 
> More precisely, is there a way to pass Select the user choice of any  
> letter using some sort of 'wildcard' value that represents any value  
> for the specific attribute, i.e.,
> 
>   Select[myData,(#[[2]]=='Wildcard' && #[[3]]==Blue)&]
> 
> My motivation is that if I have may possible selection criteria, I  
> can still use a single Select statement.
> 
> Thanks,
> 
> -Mark
> 


  • Prev by Date: Re: Using Select
  • Next by Date: Re: Using Select
  • Previous by thread: Re: Using Select
  • Next by thread: Re: Using Select