cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
RA899
Level IV

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

Recommended Articles