Subscribe Bookmark RSS Feed

Copying Columns and Column Names to a New Table

abdulj

Community Trekker

Joined:

Jul 12, 2011

Hello

I'm having a bit of trouble selecting columns from a data table and copying them to a new blank table.

So far I'm stuck on how to even copy the column names to the new table.

In my workflow I prompt the user to select 2 data column from an existing table using the column dialog function, then from there attempt to move everything over.

Here's the code:

CD = Column Dialog(

          Col1 = ColList( "Select First Data Column", Min Col( 1 ), Max Col(1) ),

          Col2 = ColList( "Select Second Data Column", Min Col( 1 ), Max Col(1) )

);

RemoveFrom(CD, 3);

name1 = r1["Col1"];

dt = New Table();

dt << New Column();

Column(1) << Set Name(char(name1));

When I use the show() command to Show(name1) I get:

{:Name( "Outer length-A-1" )}

Instead of just "Outer length-A-1"

Which means my column name ends up being {:Name( "Outer length-A-1" )}

How do I reference just this name??

Also, is there a built in function for simply copying the entire column to my new table??

thanks


1 ACCEPTED SOLUTION

Accepted Solutions
Solution

This uses the subset command and might be a little simpler:

dt1 = open("$sample_data\big class.jmp");

col_dlg = new window("Column Copier",

      panelbox("Select two columns to create a new table with:",

            col_clist = collistbox(all, width(200), max selected(2)),

      ),

      buttonbox("OK",

            selected_column_list = col_clist << getselected;

            col1 = selected_column_list[1];

            col2 = selected_column_list[2];

// Create a new table using just the two selected columns

            dt2 = dt1 << Subset( columns(column(dt1, col1), column(dt1, col2) ) );

            col_dlg << close window;

      )

);

3 REPLIES
ms

Super User

Joined:

Jun 23, 2011

I think the easiest would be the subset() command. You get both the column names and data in one sweep.

dt1 = current datatable();

CD = Column Dialog(

          Col1 = ColList( "Select First Data Column", Min Col( 1 ), Max Col(1) ),

          Col2 = ColList( "Select Second Data Column", Min Col( 1 ), Max Col(1) )

);

RemoveFrom(CD, 3);

dt1 << subset(

          rows( 1 :: N Rows( dt1 ) ),

  Eval List( CD ),

          Output Table Name( "e.g. New Table" )

)


Solution

This uses the subset command and might be a little simpler:

dt1 = open("$sample_data\big class.jmp");

col_dlg = new window("Column Copier",

      panelbox("Select two columns to create a new table with:",

            col_clist = collistbox(all, width(200), max selected(2)),

      ),

      buttonbox("OK",

            selected_column_list = col_clist << getselected;

            col1 = selected_column_list[1];

            col2 = selected_column_list[2];

// Create a new table using just the two selected columns

            dt2 = dt1 << Subset( columns(column(dt1, col1), column(dt1, col2) ) );

            col_dlg << close window;

      )

);

abdulj

Community Trekker

Joined:

Jul 12, 2011

Great thanks for this.

Another new function I now know about.