MathGroup Archive 2009

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

Search the Archive

Re: Selecting Rows Based on Column Values

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101611] Re: [mg101471] Selecting Rows Based on Column Values
  • From: "Elton Kurt TeKolste" <tekolste at fastmail.us>
  • Date: Fri, 10 Jul 2009 23:25:16 -0400 (EDT)
  • References: <200907081110.HAA12236@smc.vnet.net>

Cynthia

I think that the index used in select is incorrect: [[All,3]] will yield
an index one longer than the depth of the addressed array.

Since each row of your matrix is a vector, you may address the component
to be used for comparison directly as #[[3]].  

In[21]:= tester={{1,3,1},{3,1,0},{4,2,1},{5,6,2}}
Out[21]= {{1,3,1},{3,1,0},{4,2,1},{5,6,2}}
In[34]:= Select[tester,(#[[3]]==1)&]
Out[34]= {{1,3,1},{4,2,1}}

Kurt TeKolste

On Wed, 08 Jul 2009 03:10 -0400, "cynthia wu" <wu.x.cynthia at gmail.com>
wrote:
> I've been trying to use the Select Command to select only the rows
> that have the a specific value in a specific column.  I have, for
> example, the following matrix (4x3):
> 
> tester={{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}}
> 
> I want to select the rows that have values ==1 in the 3rd column.
> I've tried:
> 
> select(tester, #[[All,3]]==1&), but I get an error saying that my
> request violates the matrix boundaries.
> 
> The desired output should be: {{1,3,1}, {4,2,1}}.
> 
> Any thoughts would be greatly appreciated.  Thanks!
> 


  • Prev by Date: question on constructing graphs
  • Next by Date: Re: Symbolic summation
  • Previous by thread: Re: Selecting Rows Based on Column Values
  • Next by thread: Re: Selecting Rows Based on Column Values