Re: How to Do a Replacement with Two Conditions

• To: mathgroup at smc.vnet.net
• Subject: [mg119714] Re: How to Do a Replacement with Two Conditions
• From: Gregory Lypny <gregory.lypny at videotron.ca>
• Date: Sat, 18 Jun 2011 06:14:35 -0400 (EDT)
• References: <201106170407.AAA28768@smc.vnet.net>

```Hi Murray,

Good stuff!  I should have thought of Boole.  I'm surprised too that
Greater is not listable.

Thanks,

Gregory

On Fri, Jun 17, 2011, at 9:48 AM, Murray Eisenberg wrote:

> I was with you until you said "to create a dummy variable". If you
just want to replace numbers > 180 with 1 and those <= 180 with 0,
then Boole will do the trick:
>
>   myList = Append[RandomInteger[{0, 360}, 10], 180]
> {235, 189, 23, 169, 229, 93, 14, 284, 251, 290, 180}
>
>   Boole[ Thread[myList > 180] ]
> {1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0}
>
> The Thread is needed because > (Greater) is not Listable -- somewhat
surprisingly to me.
>
>
> On 6/17/2011 12:07 AM, Gregory Lypny wrote:
>> Hello everyone,
>>
>> I have a list of integers and I want to replace numbers bigger than
180 with one and those less than or equal to 180 with 0 to create a
dummy variable.  The ones are easy:
>>
>> 	myList /. x_ /; x>  180 ->  1
>>
>> How do I get the zeros in there?
>>
>> Regards,
>>
>> Gregory
>>
>
> --
> 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

```

• Prev by Date: Re: How to Do a Replacement with Two Conditions
• Next by Date: Re: Metastable expressions in Mathematica
• Previous by thread: Re: How to Do a Replacement with Two Conditions
• Next by thread: Re: How to Do a Replacement with Two Conditions