cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
RA899
Level III

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.

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

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;
Jim

View solution in original post

jthi
Super User

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);
-Jarmo

View solution in original post

2 REPLIES 2
txnelson
Super User

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;
Jim
jthi
Super User

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);
-Jarmo