Subscribe Bookmark RSS Feed

JSL to select cells to copy to another table

SamH

Contributor

Joined:

Mar 3, 2017

hi everyone, sorry to jmp in on this conversation. I am new to JSl scripting.
I have table with thousands of rows. I need to be able to select a group of cells in one column, so I could copy it into another table. for example for Column: "Test3 (VOLTS)" only 1000 rows; I need to copy cells from row 50 thru row 200 using JSL code.
Thanks SAM

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp

Staff

Joined:

Jun 23, 2011

Solution

Please find one way to do this:

NamesDefaultToHere(1);
 // Get some data
 dt = Open("$SAMPLE_DATA/Big Class.jmp");
 // Suppose we want the values in rows 10 to 32 in the column containing 'weight'
 vals = Column(dt, "weight")[10::32];
 // Put these in a new table
 dt2 = NewTable("Result", NewColumn("weight", Numeric, Continuous, Values(vals)));
4 REPLIES
ian_jmp

Staff

Joined:

Jun 23, 2011

Solution

Please find one way to do this:

NamesDefaultToHere(1);
 // Get some data
 dt = Open("$SAMPLE_DATA/Big Class.jmp");
 // Suppose we want the values in rows 10 to 32 in the column containing 'weight'
 vals = Column(dt, "weight")[10::32];
 // Put these in a new table
 dt2 = NewTable("Result", NewColumn("weight", Numeric, Continuous, Values(vals)));
Eduardo

New Contributor

Joined:

Aug 5, 2017

Thanks for this nice answer Jan. How would the code look like if I would have liked to copy the entire column include its name? Without having to name the new column. Something like: copy column with its name, paste column to new table with its name. Cheers! Eduardo.
ms

Super User

Joined:

Jun 23, 2011

You could use the Subset() function to "copy" cells to a new table. It's very versatile and allows for conditional row selection.

 

A column can also be copied by getting and evaluating its script. See the JSL examples of both approaches below.

dt1 = Open("$sample_data\big class.jmp");
dt2 = New Table("another table", New Column("data", values(1 :: 10)));
// Copy column "height" to another table (here from dt1 to dt2)
Eval(Eval Expr(dt2 << Expr(dt1:height << get script)));

//Or more direct: use Subset()
// "Copy" entire column(s)
dt_new = dt1 << Subset(Columns(height), All rows(1));
// Or copy conditionally
dt2_new = dt1 << Subset(Columns(height), Rows(dt1 << get rows where(height > 62)));

 

txnelson

Super User

Joined:

Jun 22, 2012

SamH,

I am looking to see if there is an issue with the Discussion Forum.  Yesterday, you entered in a discussion question "Select a group of cells in a column" which is virtually identical to this discussion.  Did yesterday's item not get displayed in the forum?  Did you forget that you had already entered in the discussion item?(I certainly have done that myself)

 

As I said, I just want to make sure there isn't a problem, where your item from yesterday didn't get processed properly.

Jim