Choose Language Hide Translation Bar
Highlighted
FN
FN
Level V

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

 

 

4 REPLIES 4
Highlighted
cwillden
Super User

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
Highlighted
FN
FN
Level V

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

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

Highlighted
cwillden
Super User

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
Highlighted
FN
FN
Level V

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

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

Article Labels

    There are no labels assigned to this post.