Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Automatic Grouping Script

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 19, 2013 6:26 PM
(3419 views)

Hello All

I need some help on what the best way would be to group multiple columns of the same table.

My table would have columns similar to the following:

Z 3 , X 1, Z 2, X 3, X 4, Y 1, X 2, Y 2, Z 1

I would like to group all the Xs, Ys and Zs together and in numeric order if possible. This is a condensed version of what I deal with which is usually on the order of hundreds of columns with varying group sizes required.

The easiest way I think would be to create a list based on the column names, then use the loc() feature to return the position of each similar column name. However, what would be the best way to use the group() command?

Any help on this problem is appreciated.

thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

There are probably several ways to do this. Here is one idea that should work for any table where grouping is to be based on the first letter of the column names.

// Example table

names = **{**Z 3, X 1, Z 2, X 3, X 4, Y 1, X 2, Y 2, Z 1**}**;

dt = New Table**(** "test" **)**;

For**(** i = **1**, i <= N Items**(** names **)**, i++,

dt << New Column**(** Char**(** names**[**i**]** **)**, numeric **)**

**)**;

// sort table columns and make list of first letter of column names

dt << reorder by name**()**;

collist = dt << get column names**(** string **)**;

For**(** i = **1**, i <= N Col**(** dt **)**, i++,

collist**[**i**]** = Left**(** collist**[**i**]**, **1** **)**

**)**;

// Make list of unique column name 1st letter

col_type = Associative Array**(** collist **)** << get keys;

// Group columns

For**(** i = **1**, i <= N Items**(** col_type **)**, i++,

pos = Loc**(** collist, col_type**[**i**]** **)**;

dt << group columns**(** Column**(** pos**[****1****]** **)**, N Row**(** pos **)** **)**;

**)**;

2 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

There are probably several ways to do this. Here is one idea that should work for any table where grouping is to be based on the first letter of the column names.

// Example table

names = **{**Z 3, X 1, Z 2, X 3, X 4, Y 1, X 2, Y 2, Z 1**}**;

dt = New Table**(** "test" **)**;

For**(** i = **1**, i <= N Items**(** names **)**, i++,

dt << New Column**(** Char**(** names**[**i**]** **)**, numeric **)**

**)**;

// sort table columns and make list of first letter of column names

dt << reorder by name**()**;

collist = dt << get column names**(** string **)**;

For**(** i = **1**, i <= N Col**(** dt **)**, i++,

collist**[**i**]** = Left**(** collist**[**i**]**, **1** **)**

**)**;

// Make list of unique column name 1st letter

col_type = Associative Array**(** collist **)** << get keys;

// Group columns

For**(** i = **1**, i <= N Items**(** col_type **)**, i++,

pos = Loc**(** collist, col_type**[**i**]** **)**;

dt << group columns**(** Column**(** pos**[****1****]** **)**, N Row**(** pos **)** **)**;

**)**;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Works great, thanks MS!

A follow up question... Is there any easy way to present the user with a list of all the groups, have them select one more groups from the list, then have the script create subset tables containing only the selected groups?