Re: Selecting Rows Based on Column Values
- To: mathgroup at smc.vnet.net
- Subject: [mg101528] Re: [mg101471] Selecting Rows Based on Column Values
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Thu, 9 Jul 2009 01:58:11 -0400 (EDT)
- References: <200907081110.HAA12236@smc.vnet.net>
Hi Cynthia,
you were just a step away. Here is the right syntax:
In[1] =
tester = {{1, 3, 1}, {3, 1, 0}, {4, 2, 1}, {5, 6, 2}};
In[2] = Select[tester, #[[3]] == 1 &]
Out[2] = {{1, 3, 1}, {4, 2, 1}}
Just keep in mind that you have to use square brackets, not parentheses,
to call functions in Mathematica.
Regards,
Leonid
On Wed, Jul 8, 2009 at 4:10 AM, 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!
>
>
- References:
- Selecting Rows Based on Column Values
- From: cynthia wu <wu.x.cynthia@gmail.com>
- Selecting Rows Based on Column Values