Re: Creating a new table using values from a column in another table,

• To: mathgroup at smc.vnet.net
• Subject: [mg66362] Re: Creating a new table using values from a column in another table,
• From: "J Siehler" <jsiehler at gmail.com>
• Date: Thu, 11 May 2006 02:14:00 -0400 (EDT)
• References: <e3sgqp\$lsf\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Here's a sample data table and two possible ways to do what you want,
one based on mapping, one based on a replacement rule.

In[1]:=
data=Table[{Prime[n],Random[]},{n,15}]

Out[1]=
{{2,0.736809},{3,0.106457},{5,0.165311},{7,0.137037},{

11,0.0934996},{13,0.0962497},{17,0.253369},{19,0.973479},{23,0.953613},{29,\
0.819286},{31,
0.603322},{37,0.487691},{41,0.392807},{43,0.550309},{47,0.249372}}

In[3]:=
{First@#,f@First@#}&/@data

Out[3]=
{{2,f[2]},{3,f[3]},{5,f[5]},{7,f[7]},{11,f[11]},{13,f[13]},{17,f[17]},{19,
f[19]},{23,f[23]},{29,f[29]},{31,f[31]},{37,f[37]},{41,f[41]},{43,
f[43]},{47,f[47]}}

In[4]:=
data/.{a_,b_}:>{a,f[a]}

Out[4]=
{{2,f[2]},{3,f[3]},{5,f[5]},{7,f[7]},{11,f[11]},{13,f[13]},{17,f[17]},{19,
f[19]},{23,f[23]},{29,f[29]},{31,f[31]},{37,f[37]},{41,f[41]},{43,
f[43]},{47,f[47]}}

Wonko the Sane wrote:
> 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

```

• Prev by Date: RE: Creating a new table using values from a column in another table,
• Next by Date: Re: NDSolve system of partial eqn
• Previous by thread: RE: Creating a new table using values from a column in another table,
• Next by thread: Re: Creating a new table using values from a column in another table,