       Re: List Manipulation: Conditionally changing y value when x value meets some criteria

• To: mathgroup at smc.vnet.net
• Subject: [mg109016] Re: List Manipulation: Conditionally changing y value when x value meets some criteria
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Sat, 10 Apr 2010 06:54:37 -0400 (EDT)

```On 4/9/10 at 3:31 AM, cjkphd at wi.rr.com (Charles Koehler) wrote:

>I joined the data using:

While this will clearly work and there is nothing wrong with it,
it seems to me more direct and clearer to do

Transpose@{x,y} or even

>I assumed that by testing the x value using #[], I could change
>the value of y using #[] as shown below.  If no manipulation was
>required based on the value of x, I would keep that point unchanged,
>but I'm definitely missing something.

>filtered=If[a<#[]&<b,#[]&=0],{#[],#[]}&,pts]

>a and b are the range of x values

One way to accomplish what you want would be to use pattern
matching as follows:

In:= x = RandomReal[1, 10];
y = RandomReal[2, 10];
Sort[Transpose[{x, y}]] /. {a_?(.2 < # < .8 &), b_} :> {a, 0}

Out= {{0.0761041, 1.91884}, {0.129938, 0.115834}, {0.304408,
0}, {0.439366, 0}, {0.505744, 0}, {0.58412, 0}, {0.616887,
0}, {0.672258, 0}, {0.808959, 0.600491}, {0.827083, 1.27203}}

Here, I sorted the x,y pairs simply to make it easy to see the
output has 0 for y whenever x is between the two specified values.

```

• Prev by Date: Formatting a symbol without evaluating it
• Next by Date: Re: Pattern to match a list of non-negative integers
• Previous by thread: List Manipulation: Conditionally changing y value when x value meets some criteria
• Next by thread: Plot and advanced filling