Re: Apply function to parts of a list

• To: mathgroup at smc.vnet.net
• Subject: [mg86371] Re: Apply function to parts of a list
• From: Bill Rowe <readnewsciv at sbcglobal.net>
• Date: Sun, 9 Mar 2008 05:06:34 -0500 (EST)

```On 3/8/08 at 5:45 AM, guerom00 at gmail.com (guerom00) wrote:

>More generally now : Again I have a list of list but with more
>"dimensions" Something like that :

>data={{x1,y1,z1,f1,g1,h1},{x2,y2,z2,f2,g2,h2},{x3,y3,z3,f3,g3,h3},..
>. {xn,yn,zn,fn,gn,hn}}

>And let's say I wanna, for the sake of the example, add 10 to all
>the y's i.e. I want

>{{x1,y1+10,z1,f1,g1,h1},{x2,y2+10,z2,f2,g2,h2},{x3,y3+10,z3,f3,g3,h3
>},... {xn,yn+10,zn,fn,gn,hn}}

>According to all your suggestions, I could do

>{#1,#2+10,#3,#4,#5,#6}& @@@ data

>Right ? Isn't there another simpler way (imagine instead of 6
>elements (x,y,z,f,g,h), I have 100 !)

A simple way to do this would be to use pattern matching. For example,

In[32]:= data = RandomReal[1, {5, 5}];

In[33]:= data /. {a_, b_Real, c__} -> {a, b + 10, c}

Out[33]= {{0.976633, 10.5061, 0.372096, 0.461543, 0.56471},
{0.248924, 10.9755, 0.94797,  0.56371, 0.826699},
{0.989176, 10.0068, 0.813585, 0.0352947, 0.429819},
{0.802074, 10.7574, 0.0873589, 0.544472, 0.467378},
{0.721198, 10.8001, 0.471152, 0.388743, 0.423209}}
--
To reply via email subtract one hundred and four

```

• Prev by Date: Re: symbolize in v.6
• Next by Date: Re: Re: Apply function to parts of a list
• Previous by thread: Re: Re: Apply function to parts of a list
• Next by thread: Re: Re: Apply function to parts of a list