- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Getting the items of a character column as a list
Hi all,
I'm simply trying to get a character column as a list. The column has duplicate entries and I would like a function that returns only the unduplicated rows. I tried using the "Get as matrix" function along with the " as column" function, but I kept getting different errors.
Any help is appreciated. Thanks.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Getting the items of a character column as a list
The easiest way I know to do this is with an Associative Array
names default to here(1);
dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
uniqueValues = associative array(dt:sex)<<get keys;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Getting the items of a character column as a list
There are few different options all with their own disadvantages and advantages. Some are slower/faster, some take more code to write,... I usually use Summarize()
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
// Use associative array + get keys (slowest)
uniqnames1 = Associative Array(Column(dt, "name")) << get keys;
// Use summarize (will convert numeric values to characters)
Summarize(dt, uniqnames2 = By(:name));
// Use summary + data table subscripting (or get values)
dt_summary = dt << Summary(
Group(:name),
Freq("None"),
Weight("None"),
Link to original data table(0),
private
);
uniqnames3 = dt_summary[0, "name"];
uniqnames4 = Column(dt_summary, "name") << get values;
Close(dt_summary, no save);
Show(uniqnames1, uniqnames2, uniqnames3, uniqnames4);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Getting the items of a character column as a list
The easiest way I know to do this is with an Associative Array
names default to here(1);
dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
uniqueValues = associative array(dt:sex)<<get keys;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Getting the items of a character column as a list
There are few different options all with their own disadvantages and advantages. Some are slower/faster, some take more code to write,... I usually use Summarize()
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
// Use associative array + get keys (slowest)
uniqnames1 = Associative Array(Column(dt, "name")) << get keys;
// Use summarize (will convert numeric values to characters)
Summarize(dt, uniqnames2 = By(:name));
// Use summary + data table subscripting (or get values)
dt_summary = dt << Summary(
Group(:name),
Freq("None"),
Weight("None"),
Link to original data table(0),
private
);
uniqnames3 = dt_summary[0, "name"];
uniqnames4 = Column(dt_summary, "name") << get values;
Close(dt_summary, no save);
Show(uniqnames1, uniqnames2, uniqnames3, uniqnames4);