Subscribe Bookmark RSS Feed

How to group columns names that ending with certain words given by user into a new column?

JT1

New Contributor

Joined:

Feb 14, 2017

Hi all,

 

I'm new to the JMP, would like to seek for some helps related to the JMP script.

Recently I am having some trouble to group all the columns together that each column variable name are ending with certain words.

eg. 1_id, 2_id, 3_id    - group into named as id_group

 

Thanks & appreciated for the great helps.

3 REPLIES
ian_jmp

Staff

Joined:

Jun 23, 2011

You can try something like this:

 

NamesDefaultToHere(1);
// Make a table with some columns having random names'
dt = NewTable("Random Column Names");
For(i=1, i<=100, i++,
	dt << NewColumn(Char(RandomInteger(10))||Char(RandomInteger(5)))
);
// Get a list of columns in the table
cols = dt << getColumnNames("String");
// Make a column group from columns with names ending in '2'
cols2group = {};
for(i=1, i<=NItems(cols), i++,
	if(EndsWith(cols[i], "2"), InsertInto(cols2group, cols[i]));
);
dt << groupColumns("Ending in 2", cols2group);
JT1

New Contributor

Joined:

Feb 14, 2017

Its working. Thanks for the great help.

David_Burnham

Super User

Joined:

Jul 13, 2011

perhaps mark it as answered?

-Dave