jmp-l
[Top] [All Lists]

Re: How to achieve this simple Column addition in JSL?

To: <jmp-l@lists.biostat.wustl.edu>
Subject: Re: How to achieve this simple Column addition in JSL?
From: "Magie, Stephen" <Stephen.Magie@netapp.com>
Date: Wed, 11 Feb 2009 10:27:44 -0800
In-reply-to: <25e89e790902110736y243dcfd5q61985823447b02a5@mail.gmail.com>
References: <25e89e790902110736y243dcfd5q61985823447b02a5@mail.gmail.com>
Thread-index: AcmMXoq866PwltLeSPy77Y560kzP0QAFpcGA
Thread-topic: [jmp-l] How to achieve this simple Column addition in JSL?

Fred,

 

Try:

 

dt = currentdatatable();

nc = ncol(dt);

nr = nrow(dt);

show(nr);show(nc);

sumcol = dt << newcolumn("sum", numeric);

for(i=1, i<=nr, i++,

 sumcol[i]=0;

 for(j=1, j<=nc, j++,

  sumcol[i] += column(dt, j)[i];

  //Show(i,j, column(dt, j)[i]);

 )

);

 

Note 3 changes:

(1)    I interchanged the nesting of the “for” loops, putting “nc” in the inner loop and “nr” in the outer loop.

(2)    I changed the increment variable for the outer loop to “i++” from the constant 1; and changed the increment variable for the inner loop to “j++” from the constant 2.

(3)    For each row, I initialized the value of sumcol to 0.  Without this initialization, each number to be added was being added to a missing value, which yields a missing value.

 

Hope this helps.

 

Regards,

Steve Magie

 

From: Fred Zhang [mailto:ieaggie2009@gmail.com]
Sent: Wednesday, February 11, 2009 7:36 AM
To: jmp-l@lists.biostat.wustl.edu
Subject: [jmp-l] How to achieve this simple Column addition in JSL?

 

Hi,

 

Just a newbie of JSL.

 

I open a data tabel (each column is numeric type).

And want to add up each other column to a new column "sum".

Given the following script, I always get the Log Comment:

invalid argument in access or evaluation of 'Column' , Column( dt, j )

Can anyone help me out?

Thanks, Fred

dt = currentdatatable();
nc = ncol(dt);
nr = nrow(dt);
show(nr);show(nc);
sumcol = dt << newcolumn("sum", numeric);
for(i=1, i<=nc, 1,
 for(j=1, j<=nr, 2,
  sumcol[i] += column(dt, j)[i];
 )
)

<Prev in Thread] Current Thread [Next in Thread>