cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
abdulj
Level IV

Copying Columns and Column Names to a New Table

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
pmroz
Super User

Copying Columns and Column Names to a New Table

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;

      )

);

View solution in original post

3 REPLIES 3
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Copying Columns and Column Names to a New Table

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" )

)


pmroz
Super User

Copying Columns and Column Names to a New Table

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
Level IV

Copying Columns and Column Names to a New Table

Great thanks for this.

Another new function I now know about.

Recommended Articles