Re: Select x s.t. y>10
- To: mathgroup at smc.vnet.net
- Subject: [mg13989] Re: [mg13957] Select x s.t. y>10
- From: Xah Lee <xah at best.com>
- Date: Sat, 12 Sep 1998 16:59:13 -0400
- Sender: owner-wri-mathgroup at wolfram.com
At 7:06 PM -0000 1998.09.11, Jason Gill wrote: >... > what I >am trying to do is take a list of lists of length 2 ie a list of x,y >coordinates, and Select x values based on some criterion for y. For >example I want to select the first x value for which the corresponding >y is greater than 5. >... Use Select or Cases. In general, there are two ways to extract elements from the list. One is based on their position, the other on properties of elements. The former is done with Take or Part, which is useful when you know the positions of elements you want. For the latter, there's Select and Cases. In Select, the selection is based on a user defined True/False function (a predicate). Cases is more general. It uses pattern matching as criterion, and user can also specify the level to extract at, and applying a transformation on elements of matched result. Note that a pattern matching and predicate are interchangable as follows: Suppose predicateQ is your predicate function, and suppose patternQ is your pattern. To turn a predicate into a pattern, use (_?predicateQ) To turn a pattern into a predicate, use Function[MatchQ[#,patternQ]] -- In your example, perhaps one of the following is useful: (Last at #>5&) or {x_, _?(#>5&)}->x. Xah, xah at best.com http://www.best.com/~xah/Wallpaper_dir/c0_WallPaper.html Perl: all unix's stupidity in one.