Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: select 1st column element based on criteria in 2nd column in mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124168] Re: select 1st column element based on criteria in 2nd column in mathematica
  • From: "Nasser M. Abbasi" <nma at 12000.org>
  • Date: Wed, 11 Jan 2012 06:01:45 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

On 1/11/2012 3:18 AM, Hani wrote:
> hello, I have a question.
>
> Suppose I have a table with two columns like this:
>
> 1  3
> 2  4
> 3  6
> 4  1
> 5  3
> 6  2
> 7  5
> 8  2
>
> I want to select elements of the 1st column which its corresponding 2nd
> column elements are bigger than 3. so, the result should be {2,3,7}.  How to
> implement that in mathematica? Thanx a lot
>

one way:

------------------------
mat = {{1, 3}, {2, 4}, {3, 6}, {4, 1}, {5, 3}, {6, 2}, {7, 5}, {8, 2}};
r   = Select[mat, #[[2]] > 3 &];
r[[All, 1]]
-----------------

another
----------------------------
mat = {{1, 3}, {2, 4}, {3, 6}, {4, 1}, {5, 3}, {6, 2}, {7, 5}, {8, 2}};
loc = Position[mat, {x_, y_} /; y > 3]
r   = Extract[mat, loc];
r[[All, 1]]
----------------------------------------

I am sure there are many more ways.

--Nasser



  • Prev by Date: Re: Unit testing using imported data
  • Next by Date: take square of the second and third column of a table
  • Previous by thread: Re: select 1st column element based on criteria in 2nd column in mathematica
  • Next by thread: Re: select 1st column element based on criteria in 2nd column in mathematica