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: [mg101554] Re: Selecting Rows Based on Column Values
  • From: cynthia wu <wu.x.cynthia at gmail.com>
  • Date: Fri, 10 Jul 2009 06:43:17 -0400 (EDT)
  • References: <200907081110.HAA12236@smc.vnet.net> <h340ua$gvm$1@smc.vnet.net>

On Jul 9, 1:58 am, Adriano Pascoletti
<adriano.pascole... at dimi.uniud.it> wrote:
> #[[All,3]] means the thirdcolumnof an array, and your triples are
> one-dimensional objects...Use #[[3]]:
>
> In[2]:= Select[tester, #[[3]] == 1 &]
> Out[2]= {{1, 3, 1}, {4, 2, 1}}
>
> Another approach
>
> In[3]:= Cases[tester, {_, _, 1}]
> Out[3]= {{1, 3, 1}, {4, 2, 1}}
>
> Adriano Pascoletti
>
> 2009/7/8 cynthia wu <wu.x.cynt... at gmail.com>
>
> > I've been trying to use the Select Command to select only therows
> > that have the a specific value in a specificcolumn.  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 therowsthat havevalues==1 in the 3rdcolumn.
> > 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!

Thank you all so much!


  • Prev by Date: RE: Is it possible to impose a condition on an iterator
  • Next by Date: Re: GeoDistance and transformation from WGS84 to WGS84
  • Previous by thread: Re: Selecting Rows Based on Column Values
  • Next by thread: Re: Selecting Rows Based on Column Values