Re: Creating a new table using values from a column in another table,
- To: mathgroup at smc.vnet.net
- Subject: [mg66365] Re: Creating a new table using values from a column in another table,
- From: Peter Pein <petsie at dordos.net>
- Date: Thu, 11 May 2006 02:14:07 -0400 (EDT)
- References: <e3sgqp$lsf$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Wonko the Sane schrieb: > Hi all, > > I have a question that I have not been able to work out myself, and so > put it to the group to help. I have a set of data points in a table (2 > columns {{x1,y1},{x2,y2},....,{xn,yn}}) I have performed a fit to the > data and have a function f[x] which I would now like to evaluate at each > data point (column 1 of the first table) to get a new table > {{x1,f[x1]},{x2,f[x2]},....,{xn,f[xn]}}. Is there a way to do this? I > hope my request is clear > > Best Regards > Michael > Coose one (there are most propably more possibilities): data = Table[ToExpression[StringJoin[#1, ToString[n]]]& /@ {"x", "y"}, {n, 5}] --> {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}, {x5, y5}} {#1, f[#1]}& /@ First /@ data --> {{x1, f[x1]}, {x2, f[x2]}, {x3, f[x3]}, {x4, f[x4]}, {x5, f[x5]}} Transpose[{#1, f /@ #1}&[First[Transpose[data]]]] --> {{x1, f[x1]}, {x2, f[x2]}, {x3, f[x3]}, {x4, f[x4]}, {x5, f[x5]}} data /. {x_?AtomQ, _} :> {x, f[x]} --> {{x1, f[x1]}, {x2, f[x2]}, {x3, f[x3]}, {x4, f[x4]}, {x5, f[x5]}} Peter