Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Replace specific element with specific value.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99650] Re: [mg99620] Replace specific element with specific value.
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Sun, 10 May 2009 05:16:27 -0400 (EDT)
  • References: <200905090722.DAA00107@smc.vnet.net>
  • Reply-to: drmajorbob at bigfoot.com

data /. {x -> x + xx, y -> y + yy, z -> z + zz}

{{0, 2}, {2, x + xx}, {3, 4}, {4, 6}, {6, y + yy}, {8, 9}, {9,
   z + zz}}

Bobby

On Sat, 09 May 2009 02:22:47 -0500, <nick.maj at mssm.edu> wrote:

> I tried this code, it gives me right and wrong results spreeded into
> nested lists.
>
> data = {{0, 2}, {2, x}, {3, 4}, {4, 6}, {6, y}, {8, 9}, {9, z}}
>
> Table[{#1, #2 + Which[#2 === j, i, #2 =!= j, 0]} & @@@
>   data, {i, {xx, yy, zz}}, {j, {x, y, z}}]
>
> needed output:
>
> {0, 2}, {2, x+xx}, {3, 4}, {4, 6}, {6, y+yy}, {8, 9}, {9, z+zz}}
>
> While searching only the second element of each list, if x is found
> add xx and if y is found add yy to it etc.
>
> How to. Thanks in advance, Nick.
>



-- 
DrMajorBob at bigfoot.com


  • Prev by Date: Re: a' vs a and a vs a' looks different in streamplot
  • Next by Date: Re: Plotting in a dynamic environment.
  • Previous by thread: Replace specific element with specific value.
  • Next by thread: Re: Replace specific element with specific value.