Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Apply function to parts of a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86297] Re: Apply function to parts of a list
  • From: Albert Retey <awnl at arcor.net>
  • Date: Fri, 7 Mar 2008 02:34:07 -0500 (EST)
  • References: <fqo8pn$svq$1@smc.vnet.net>

Hi,
> Very often, I find myself having datas to plot of this form :
> 
> data={{x1,y1},{x2,y2},{x3,y3}...{xn,yn}}
> 
> So, very conventional : a list of abscissa and ordinate. Now, let's say I want to multiply by 2 all my ascissa. Right now, I write :
> 
> MapAt[2*#&,data,Table[{i,1},{i,1,Length[data]}]]
> 
> It's OK but I isn't there another way to achieve this as I find this rather "involved" for such a simple thing ?

I'm sure you will get many good variations of how to do that. Here are 
my 2 cents:

Replace[data, {x_, y_} -> {2*x, y}, {1}]

Map[{2, 1}*# &, data]


hth,

albert


  • Prev by Date: Re: Apply function to parts of a list
  • Next by Date: Re: Apply function to parts of a list
  • Previous by thread: Re: Apply function to parts of a list
  • Next by thread: Re: Apply function to parts of a list