Fred,
Change j++ to j+2. That will increment j by 2 è 1,
3,5,7…
To get a subset of a table, simply select the columns and rows
you want in your new table and issue the subset message to the table, i.e.
dt<<subset;
or
dt<<subset(Output
Table Name("New_Tbl_Name"));
The first statement will bring up a menu where you can further
specify options, whereas the second statement will create the subset with the
table name you specify.
To select a column in a script, sent a “” message to
the column. For example, to select a column named C1 in datatable dt:
dt:C1<<Set Selected (1);
If no rows are already
selected, this statement will select all the rows in column C1.
If you want a subset of the
rows, then send a Select Where message to the table. For example,
dt << Select Where (:C1<5);
Have fun!
Regards,
Steve Magie
From: Fred Zhang
[mailto:ieaggie2009@gmail.com]
Sent: Wednesday, February 11, 2009 10:44 AM
To: jmp-l@lists.biostat.wustl.edu
Subject: Re: [jmp-l] How to achieve this simple Column addition in JSL?
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.
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
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];
)
)
|
|