cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
FN
FN
Level VI

How to duplicate a column (exact copy except header)

I am not sure what is the fastest way to duplicate a column in JMP 14.

 

Same information (data, metadata, formula) but a different header (column name copy, for example).

 

 

6 REPLIES 6
cwillden
Super User (Alumni)

Re: How to duplicate a column (exact copy except header)

From a point-and-click perspective, the shortest way I know is still a 2 step process.  You copy/paste the data with a typical Ctrl+C/Ctrl+V operation.  You copy/paste the meta data (column properties) by right clicking on a column header of a column you want to duplicate > Copy Column Properties, right click on new copy column > Paste Column Properties.

-- Cameron Willden
FN
FN
Level VI

Re: How to duplicate a column (exact copy except header)

Thanks. Scripting is definitely an option if there is no better way.

cwillden
Super User (Alumni)

Re: How to duplicate a column (exact copy except header)

The easiest thing is to use eval(:col << Get Script).  You will get a copy of the column with an integer at the end to give it a unique name.  You would need to make sure the table you want to do the operation on is the current table.

 

Here's a handy function you could use in a script that lets you name the resulting new column and specify the data table.  The only required argument is the first one, colname.  You can specify a data table, but it will assume Current Data Table() otherwise.  If you don't specify a name, it will return the original column name + " - Copy".

Names Default to Here(1);

DupCol = function({colname, new = "", dt = Current Data Table() },
	col = Column(dt, colname);
	
	if(IsMissing(new), new = colname||" - Copy");
	
	col_script = char(col << Get Script);
	col_script = substitute(col_script, "New Column", "dt << New Column");
	col_script = substitute(col_script, colname, new);
	eval(parse(col_script));
);

I'll illustrate using the Football sample data (and Big Class to show robustness of the function):

football_dat = Open("$SAMPLE_DATA/Football.jmp");
DupCol("Height"); //Produces copy of Height named "Height - Copy"
DupCol("Height", new = "Height Again"); //Produces copy of Height named "Height Again"

Open("$SAMPLE_DATA/Big Class.jmp"); //just to show robustness since this data table also has a column named "height"

//Different ways to specify the data table if not wanting to assume Current Data Table
DupCol("Height", new = "Height Once More", dt = Data Table("Football") );
DupCol("Height", new = "Height Last Time", dt = football_dat ); 

 

-- Cameron Willden
FN
FN
Level VI

Re: How to duplicate a column (exact copy except header)

Thanks. And If I want to copy the current column which is selected/highlighted?

txnelson
Super User

Re: How to duplicate a column (exact copy except header)

This snippet of code will return the name of the currently selected column

colName = (current data table() << get selected columns)[1];
Jim
jetpeach
Level II

Re: How to duplicate a column (exact copy except header)

just an FYI for those using this - i've been using this function periodically, but have had it hang jmp on larger datatables (>100k rows). i haven't thoroughly debugged - but i did find the clone a column thread here (basically the same, except no char() conversion of the script and no substitutions - i'm setting naming using expressions instead) was ~5x faster and i'm hoping won't die in whatever corner cases are causing hang for me.  i'm switching my addin to use something based on that, and hoping it is less likely to crash.

 

https://community.jmp.com/t5/Discussions/clone-a-column/td-p/15644