MathGroup Archive 1995

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

Search the Archive

Re: any better to apply a function to second column?


On Tue 07 Mar 1995, Richard Chen wrote:

> 	Suppose I have list of numbers in pairs:
> 

a = {{x1,y1},{x2,y2},...,{xn,yn}}

> I would like to apply to the sequence {y1,y2,...,yn} the function
> f so that a new sequence
> 

> b = {{x1,f[y1]},{x2,f[y2]},...,{xn,f[yn]}}
> 

> is generated.
> 

> My current solution is
> 

> b = Transpose[{First /@ a,f[Last /@ a]}]
> 

> However, I suspect there should be a much more simpler way than this.
> 

> Does any body know a more straight forward way to do this?

Yes.

Map[MapAt[f, #, 2]&, a]

will accomplish what you want.

> Also, what if I have a matrix of 3 or more columns and I would apply
> f to only the second column, say. What is a better way in this case?

The same instruction works in this case as well.

--Lou Talman
  Metropolitan State College of Denver


  • Prev by Date: Graphics on a NeXT into MSWord on a PC?
  • Next by Date: Re: Numerical evaluation of HypergeometricPFQ[{a,b,c},{d,e},1]
  • Previous by thread: Re: any better to apply a function to second column?
  • Next by thread: Re: any better to apply a function to second column?