MathGroup Archive 1998

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

Search the Archive

Re: Select x s.t. y>10

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13996] Re: [mg13957] Select x s.t. y>10
  • From: Wouter Meeussen <eu000949 at pophost.eunet.be>
  • Date: Sat, 12 Sep 1998 16:59:19 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Jason,

patterns with conditions are nice constructs :
 
it={{a,1},{b,3},{c,4},{d,9},{e,7}}

Cases[it,{_,x_?PrimeQ}]
First/@Cases[it,{_,x_?PrimeQ}]
 
{{b,3},{e,7}}
{b,e}

if your criteria for selection do not involve a standard "yes-or-no"
returning test, then make your own:

Cases[it, {_,_?myowntestQ}] or
explicitely with a "/;condition" structure :

Cases[it,{_,x_}/;(IntegerQ[Sqrt[x]])]
First/@Cases[it,{_,x_}/;(IntegerQ[Sqrt[x]])]
 
{{a,1},{c,4},{d,9}}
{a,c,d}

wouter
******************************************

At 15:06 11-09-98 -0400, Jason Gill wrote:
>I came across what seems like it should be a simple little function, but
>could not come up with a clever way to implement it.  Generally, what I
>am trying to do is take a list of lists of length 2 ie a list of x,y
>coordinates, and Select x values based on some criterion for y.  For
>example I want to select the first x value for which the corresponding
>y is greater than 5.
>I can write a function using Position and Take etc. , but there must be
>a clever,and more efficient way to do this.  Any thoughts... Jason
>
>--
>Jason Gill
>IBM Microelectronics
>Essex Junction, VT 05452
>Phone   (802)769-3350
>Fax     (802)769-1220
>email:  jgill at vbimail.champlain.edu
>           jasongil at us.ibm.com
>
>
>
Dr. Wouter L. J. MEEUSSEN
w.meeussen.vdmcc at vandemoortele.be
eu000949 at pophost.eunet.be



  • Prev by Date: Re: Re: Vectors
  • Next by Date: Re: Abstract data types
  • Previous by thread: Re: Select x s.t. y>10
  • Next by thread: Re: Select x s.t. y>10