Re: select 1st column element based on criteria in 2nd AND 3rd column
- To: mathgroup at smc.vnet.net
- Subject: [mg124501] Re: select 1st column element based on criteria in 2nd AND 3rd column
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Sun, 22 Jan 2012 07:19:28 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
Your expression doesn't work because its syntax is wrong! First, there's no such built-in function AND in Mathematica. There is a function And, which in the present context you would probably want to use by means of its input shortcut &&. Second, if you use the Slot function (#), you need to construct a pure function by terminating with a & symbol. Thus: Select[pairs, 5 >= #[[2]] >= 3 && 10 >= #[[3]] >= 7 &] {{5, 3, 9}} For clarity, the above Select expression means the same thing as: Select[pairs, (5 >= #[[2]] >= 3 && 10 >= #[[3]] >= 7) &] On 1/21/12 5:20 AM, hanciong awesome wrote: > Hello all, suppose I have a table: > > pairs = {{1, 3, 4}, {2, 4, 6}, {3, 6, 7}, {4, 1, 8}, {5, 3, 9}, {6, 2, > 10}, {7, 5, 11}, {8, 2, 13}, {2, 3, 4}, {5, 6, 7}} > > how to select rows for which the 2nd column is between 3 and 5, AND > the 3rd column is between 7 and 10? So I want to do something similar > to this: > > Select[pairs, 5>= #[[2]]>= 3& AND 10>= #[[3]]>= 7] > > but I just couldn't get it to work. what should I do? Thank you > -- Murray Eisenberg murray at math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305