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: Fred Zhang <ieaggie2009@gmail.com>
Date: Wed, 11 Feb 2009 13:44:19 -0500
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=6E/Uz/kplAZl2jrS62yP0xQiCPpJNTiRcXpIo6SQdFs=; b=AFMcBeLXtVG8UiKfNxpxX7GoYM7h20L3sg20jZW0DYcGbGIohsq3pqib29EgTik2sv 6axXSPSIb3s6W2XyfiXwpULwEVD+a65NaBELYfcUXY7uIsbAJfHXw4CF85uChcTfZzjx MXjp3/yrzUx+j9Z+O/TElnHOpjZLzjDcyaNmE=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=TADhBUdmcTi3jVr9pXVbuu+YvGwKmpKGjCFwJ+/hwlpiDl8W5YSmSeMOFnbbhmGTiv Hn0t3pmFlQE0fDeN8m7yERzSHingJd5MoLzmDyTIUvCKtMJtYwaHW9rA0GSvoDz4AZV3 5PETSOC2KsiWLAp1wMEeZUgjsn6FPUebREtro=
In-reply-to: <2E1EB2CF9ED1CB4AA966F0EB76EAB443023E1F75@SACMVEXC2-PRD.hq.netapp.com>
References: <25e89e790902110736y243dcfd5q61985823447b02a5@mail.gmail.com> <2E1EB2CF9ED1CB4AA966F0EB76EAB443023E1F75@SACMVEXC2-PRD.hq.netapp.com>
Thanks, Steve.
 
But if  I need to sum the columns each the other, i.e. col1+col3+col5+.., should I change j++ to constant '2"?
 
Another question, if I have to extract the subset of current datatable to a new table by keeping the same column name,
what's the simple way to achieve?
For example, for current table Dt1, with nr rows and nc columns.
I want to choose the list of columns col_list, and rows from row_start to row_end.
What's the JSL would be?
 
Sorry to bother again.
Fred

2009/2/11 Magie, Stephen <Stephen.Magie@netapp.com>

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>