Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: finding positions of elements in a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86786] Re: [mg86761] finding positions of elements in a list
  • From: "Thomas Dowling" <thomasgdowling at gmail.com>
  • Date: Fri, 21 Mar 2008 01:52:04 -0500 (EST)
  • References: <200803200755.CAA29380@smc.vnet.net>

Hello,

Maybe something like the following?

mylistnew = {{20, 79}, {20, 80}, {20, 81}, {20, 109}, {20, 110}, {20,
   111}, {21, 105}, {21, 106}, {21, 107}}

With Select:

Select[mylistnew , Part[#, 2] > 80 &  ]

Out[59]= {{20, 81}, {20, 109}, {20, 110}, {20, 111}, {21, 105}, {21, 106},
{21,
   107}}

With Cases

Cases[mylistnew, {_, x_ /; x > 80}]

Out[84]= {{20, 81}, {20, 109}, {20, 110}, {20, 111}, {21, 105}, {21, 106},
{21,
   107}}

Perhaps DeleteCases also worth considering?

DeleteCases[mylistnew, {_, x_ /; x <= 80}]

Out[83]= {{20, 81}, {20, 109}, {20, 110}, {20, 111}, {21, 105}, {21, 106},
{21,
   107}}

Tom Dowling

On Thu, Mar 20, 2008 at 7:55 AM, PeterM <metaxas at lps.u-psud.fr> wrote:

> Hi.
>
> Having a few problems here with what I think should be a simple operation.
> I have a list as shown:
>
> mylist={{20, 109}, {20, 110}, {20, 111}, {21, 105}, {21, 106}, {21,
> 107},...}
>
> It's a list of {x,y} co-ordinates of some data points I'm analysing.
>
> I want to create a new list which contains only those data points whose y
> co-ordinate is greater than 80 ie. mylist[[n,2]]>80.
>
> Problem is, I can't work out how to use Select to do this when each
> element in the list has an x and a y co-ordinate. If I split the list into x
> and y co-ordinates and searched for those y values greater than 80, I would
> have a list of those y-values but would not know the corresponding x-values.
>
> I also tried Position but it wasn't clear to me if a pattern can be used
> for this.
>
> Thanks in advance, Pete.
>
>



  • Prev by Date: Re: finding positions of elements in a list
  • Next by Date: Poisson equation with boundary conditions on rectangle
  • Previous by thread: RE: finding positions of elements in a list
  • Next by thread: Re: finding positions of elements in a list