Re: How to Do a Replacement with Two Conditions

• To: mathgroup at smc.vnet.net
• Subject: [mg119713] Re: How to Do a Replacement with Two Conditions
• From: Murray Eisenberg <murray at math.umass.edu>
• Date: Sat, 18 Jun 2011 06:21:42 -0400 (EDT)
• References: <201106170407.AAA28768@smc.vnet.net>

```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}

{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: Partition a list based on columns
• Next by Date: Re: capacitor equation solution not working
• Previous by thread: Re: How to Do a Replacement with Two Conditions
• Next by thread: Re: How to Do a Replacement with Two Conditions