- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Get Column Names from List of Columns
Names Default to Here(1);
dt = Current Data Table();
column list = dt << Get Column Names(Continuous);
key list = dt << Get Column Group("KEYS");
"column list" contains a list of names from columns containing continuous data.
"key list" contains a list of columns in the "KEYS" group.
How do I get the names of the columns from "key list"? Ultimately I would like to remove any continuous column names from the "column list" that are in the "KEYS" group. I found a post from Craige Hales to manage the lists, but I need to get them in the same format.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get Column Names from List of Columns
Here is the solution I arrived at after converting the key list to strings as suggested:
// Initialize
Names Default to Here(1);
dt = Current Data Table();
key list names = {};
// Get a list of all continuous columns
column list = dt << Get Column Names(Continuous, String);
// Create a list of column names in the KEYS group
key list = dt << Get Column Group("KEYS");
For(i = 1, i <= N Items(key list), i++,
Insert Into(key list names, Char(key list[i]))
);
// Remove from the column list any column that is in the KEYS group
/* Adapted from - Re: Quick way to compare two lists (uncommon elements)?
JAN 10, 2017 6:41 AM, by Craige_Hales, STAFF (RETIRED)
*/
set1 = Associative Array(column list);
set2 = Associative Array(key list names);
// Find the names common to both lists
intersection = set1;
intersection << Intersect(set2);
// Remove the common names
cleaned list = set1;
cleaned list << Remove(intersection);
column list = cleaned list << Get Keys;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get Column Names from List of Columns
What is returned from both the << Get Column Names, and << Get Column Group are JMP lists. You can roughly think of them as Arrays of values. Please review the Scripting Guides section on using lists.
Below is a modification of your code, that will check for the comparison between 2 lists, for column names found common in both lists and then removing them from the Key List, list. Please note, that the Contains function requires literal strings for it to function, so that is why the <<get column names has the "string" option added to it, and that the Contains() function has the search element from the Keys List, converted to a character string before the search across the Column Names list.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );
column list = dt << Get Column Names( Continuous, string );
key list = dt << Get Column Group( "Processes" );
Show( "complete list", key list );
For( i = N Items( key list ), i >= 1, i--,
If( Contains( column list, Char( key list[i] ) ),
key list = Remove( key list, i, 1 )
)
);
Show( "final list", key list );
In my example, the Keys List ends up not having any values, since all elements in the group are numeric columns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get Column Names from List of Columns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get Column Names from List of Columns
Here is the solution I arrived at after converting the key list to strings as suggested:
// Initialize
Names Default to Here(1);
dt = Current Data Table();
key list names = {};
// Get a list of all continuous columns
column list = dt << Get Column Names(Continuous, String);
// Create a list of column names in the KEYS group
key list = dt << Get Column Group("KEYS");
For(i = 1, i <= N Items(key list), i++,
Insert Into(key list names, Char(key list[i]))
);
// Remove from the column list any column that is in the KEYS group
/* Adapted from - Re: Quick way to compare two lists (uncommon elements)?
JAN 10, 2017 6:41 AM, by Craige_Hales, STAFF (RETIRED)
*/
set1 = Associative Array(column list);
set2 = Associative Array(key list names);
// Find the names common to both lists
intersection = set1;
intersection << Intersect(set2);
// Remove the common names
cleaned list = set1;
cleaned list << Remove(intersection);
column list = cleaned list << Get Keys;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get Column Names from List of Columns
(I never thought of casting the column reference into a string)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get Column Names from List of Columns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get Column Names from List of Columns
Please do not bang your head! Use Help > Scripting Index instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Get Column Names from List of Columns
Here's an easy task you can help me with - once I "get column names", how can I then insert them into a data table which is just that selfsame list of column names? THANKS Devin