Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3135 > unrolled thread

How to Do a Replacement with Two Conditions

Started byGregory Lypny <gregory.lypny@videotron.ca>
First post2011-06-17 04:08 +0000
Last post2011-06-18 21:44 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  How to Do a Replacement with Two Conditions Gregory Lypny <gregory.lypny@videotron.ca> - 2011-06-17 04:08 +0000
    Re: How to Do a Replacement with Two Conditions Ray Koopman <koopman@sfu.ca> - 2011-06-17 09:51 +0000
    Re: How to Do a Replacement with Two Conditions Peter Breitfeld <phbrf@t-online.de> - 2011-06-17 10:09 +0000
    Re: How to Do a Replacement with Two Conditions Dan <dflatin@rcn.com> - 2011-06-18 21:44 +0000

#3135 — How to Do a Replacement with Two Conditions

FromGregory Lypny <gregory.lypny@videotron.ca>
Date2011-06-17 04:08 +0000
SubjectHow to Do a Replacement with Two Conditions
Message-ID<itejv3$s36$1@smc.vnet.net>
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

[toc] | [next] | [standalone]


#3158

FromRay Koopman <koopman@sfu.ca>
Date2011-06-17 09:51 +0000
Message-ID<itf839$21l$1@smc.vnet.net>
In reply to#3135
On Jun 16, 9:08 pm, Gregory Lypny <gregory.ly...@videotron.ca> 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

mylist = {179, 180, 181, 182};
UnitStep[mylist - 181]

{0, 0, 1, 1}

[toc] | [prev] | [next] | [standalone]


#3168

FromPeter Breitfeld <phbrf@t-online.de>
Date2011-06-17 10:09 +0000
Message-ID<itf94l$2ed$1@smc.vnet.net>
In reply to#3135
Gregory Lypny wrote:

You may use Unitize

ll = {52, 5, 235, 256, 259, 4, 64, 233, 92, 201, 180}
Unitize[ll, 180]
Unitize[ll, 181]

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

-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

[toc] | [prev] | [next] | [standalone]


#3171

FromDan <dflatin@rcn.com>
Date2011-06-18 21:44 +0000
Message-ID<itj673$k3o$1@smc.vnet.net>
In reply to#3135
On Jun 17, 12:08 am, Gregory Lypny <gregory.ly...@videotron.ca> 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

Clip is made for this kind of problem.

Clip[myList-180,{0,1}]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web