Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #3135 > unrolled thread
| Started by | Gregory Lypny <gregory.lypny@videotron.ca> |
|---|---|
| First post | 2011-06-17 04:08 +0000 |
| Last post | 2011-06-18 21:44 +0000 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
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
| From | Gregory Lypny <gregory.lypny@videotron.ca> |
|---|---|
| Date | 2011-06-17 04:08 +0000 |
| Subject | How 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]
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2011-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]
| From | Peter Breitfeld <phbrf@t-online.de> |
|---|---|
| Date | 2011-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]
| From | Dan <dflatin@rcn.com> |
|---|---|
| Date | 2011-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