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
shazaaliah
Level I

How to use text to column methods but without manually renaming all the splited columns afterwards?

How do I use the "text to column" method but without manually renaming all the splitted columns afterwards?

2 REPLIES 2
txnelson
Super User

Re: How to use text to column methods but without manually renaming all the splited columns afterwards?

 How would you want the new columns named?

Jim

Re: How to use text to column methods but without manually renaming all the splited columns afterwards?

Hi,

 

There are a few ways to do this.

 

Scripting:

Names Default To Here(1);

dt = open("ExTable.jmp");

//find column position of column to be split
columnPosition = contains(dt << get column names(string), "CombinedFields");

//determine original number of columns
originalNumCols  = ncol(dt);

//new names here...
newColNames = {"Model", "Country", "Type"};

//split the column
dt << Text to Columns( columns( :CombinedFields ), Delimiters( "," ) );

//how many new columns are there?
numColsCreated = ncol(dt) - originalNumCols;

//loop through the new columns, using original column's position as an offset, and change names
for(i = 1, i<=numColsCreated, i++,
	column(dt, columnPosition + i) << set name(newColNames[i])
);

Cut and paste:

Place the new column names in a single column of a table, select them all, and copy them with a CTRL-C (CMD-C on Mac).

 

brady_brady_0-1626444518417.png

 

Perform the Text To Columns operation, then select the new columns and press CTRL-V to paste the new names.

brady_brady_1-1626444593510.png

brady_brady_2-1626444648075.png

 

Using Recode Column Names

 

First, use Text To Columns to split the column of interest.

 

Next, Select Cols > Column Names > Recode Column Names... from the main menu.

brady_brady_3-1626444750071.png

 

Enter the new column names as desired, then click the Recode button to finish.

brady_brady_4-1626444822036.png

 

Table and script attached.

 

Cheers,

Brady