cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

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

Simple "Duplicate Column" method

Can anyone think of a simple way of duplicating a selected column in a data table? Basically, I'd like to select the column, and get a "Copy Of" with all the attributes, values, etc. right next to the original, in a single menu item click. Doing it by adding, moving, setting types, copying values etc. is a pain. I suppose it could be scripted as an Add-In but I was hoping that there was a simpler way.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Simple "Duplicate Column" method

Try something like this. It supports selection and copying of multiple columns.

Names Default To Here( 1 );

dt = Current Data Table();

cols = dt << get selected columns;

For( i = 1, i <= N Items( cols ), i++,

  dt << clear column selection;

  colscr = cols[i] << getscript;

  (Eval( Substitute( Name Expr( colscr ), Arg( Name Expr( colscr ), 1 ), "Copy of " || (cols[i] << get name) ) )) << set selected( 1 );

  dt << move selected columns( After( cols[i] ) );

);


View solution in original post

3 REPLIES 3

Re: Simple "Duplicate Column" method

So I created this as an Add-In. The bottom part (commented out) was an attempt to copy Column Properties but it didn't work. (This was what I was trying to avoid, but I had a long meeting with nothing better to do...) I'd still be interested if there's something more elegant than this approach.

dt = Current Data Table();

selcol = dt << Get Selected Columns;

selcolname = dt:selcol << Get Name();

newcname = "Copy Of " || selcolname;

newc = dt << New Column( newcname );

newclist = dt:newc << Get Name(); //in case this is a second copy!

movestr = "dt << Move Selected Columns({\!"%newclist%\!"}, After(\!"%selcolname%\!") );";

eval insert into(movestr,"%");

movestrexpr = Parse(movestr);

movestrexpr;

For Each Row(dt:newc = dt:selcol);

/*proplist = dt:selcol << Get Properties List();

for(i=1, i < N Items(proplist), i ++,

    currprop = Char(proplist);

    gotpropstr = "gotprop = dt:selcol << Get Property(\!"%currprop%\!");";

    eval insert into(gotpropstr,"%");

    gotpropstrexpr = Parse(gotpropstr);

    gotpropstrexpr;

    setpropstr = "newc << Eval List(Set Property(\!"%currprop%\!", List(gotprop)));";

    eval insert into(setpropstr,"%");

    setpropstrexpr = Parse(setpropstr);

    setpropstrexpr;

);

newcproplist = dt:newc << Get Properties List();

//Show Properties(dt:selcol);

*/

ms
Super User (Alumni) ms
Super User (Alumni)

Re: Simple "Duplicate Column" method

Try something like this. It supports selection and copying of multiple columns.

Names Default To Here( 1 );

dt = Current Data Table();

cols = dt << get selected columns;

For( i = 1, i <= N Items( cols ), i++,

  dt << clear column selection;

  colscr = cols[i] << getscript;

  (Eval( Substitute( Name Expr( colscr ), Arg( Name Expr( colscr ), 1 ), "Copy of " || (cols[i] << get name) ) )) << set selected( 1 );

  dt << move selected columns( After( cols[i] ) );

);


Re: Simple "Duplicate Column" method

Thanks, getscript is exactly what I was missing in my scripting knowledge!

Recommended Articles