Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: normalize a table

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72804] Re: [mg72768] normalize a table
  • From: János <janos.lobb at yale.edu>
  • Date: Sat, 20 Jan 2007 03:32:45 -0500 (EST)
  • References: <200701190601.BAA28573@smc.vnet.net>

On Jan 19, 2007, at 1:01 AM, Ruth wrote:

> Hi,
>
> I want to do something really simple, which is take a table made of
> pairs and normalize the first number in each pair by dividing by the
> largest.
>
> For instance, I want to transform this list
>
> {{1,0.2},{2,0.3},{3,0.4},{4,0.5}}
>
> into this one
>
> {{1/4, 0.2}, {1/2, 0.3}, {3/4, 0.4}, {1, 0.5}}
>
> The way i did it is through the chain of commands
>
> firsttable={{1,0.2},{2,0.3},{3,0.4},{4,0.5}};
>
>
> top=Max[Table[firsttable[[i,1]],{i,1,Length[firsttable]}]];
>
>
> mytable=Do[newtable=ReplacePart[newtable,newtable[[i,1]]/top,{i,
> 1}],{i,1,Length[firsttable]}]
>
> There must be a more elegant way to do it, but @&# and commands like
> those are still hard to handle for me, and I could not work it out
>
> Thanks in advance,
>
> Ruth
>

Here is a newbie approach:

In[9]:=
({#1[[1]]/Max[tbl[[All,1]]],
     #1[[2]]} & ) /@ tbl
Out[9]=
{{1/4, 0.2}, {1/2, 0.3},
   {3/4, 0.4}, {1, 0.5}}

János


----------------------------------------------
Trying to argue with a politician is like lifting up the head of a  
corpse.
(S. Lem: His Master Voice)


  • Prev by Date: General Mathematica and Financial Mathematics Courses
  • Next by Date: how to quickly read a >10MB big file
  • Previous by thread: Re: normalize a table
  • Next by thread: Re: normalize a table