any better to apply a function to second column?
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg507] any better to apply a function to second column?
- From: Richard Q. Chen <chen at fractal.eng.yale.edu>
- Date: Sun, 5 Mar 95 11:25:35 EST
Hi,
I would like to know if there is a better way to
do the following.
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?
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?
Thanks for any info
Richard