Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Super User
JSL Set Operations

A question about using sets of column names. You can use JSL's associative arrays to perform set operations. The methods <<Intersect, <<Remove, and <<Insert do the work.

// make three sets
rgb = associativearray({"red","green","blue"});
cmy = associativearray({"cyan","magenta","yellow"});
bw = associativearray({"black","white"});
// join them together
all = rgb;
show(all<<getkeys); // {"black", "blue", "cyan", "green", "magenta", "red", "white", "yellow"}
// take two from set
two = associativearray({"magenta","red"});
show(all<<getkeys); //{"black", "blue", "cyan", "green", "white", "yellow"}
// find common colors
rainbow = associativearray({"orange","cyan","green","red","blue"});
show(all<<getkeys); // {"blue", "cyan", "green"}

The question was posed in terms of sets of column names, and this example uses the associative array set operation <<remove to get the difference between the set of all columns and the set of columns containing the letter "i".


// keep only the columns with an "i" in the name

dt = Open( "$SAMPLE_DATA/Big" );
allnames = dt << getcolumnnames( "string" );

inames = {};
For( i = 1, i <= N Items( allnames ), i++,
	If( Contains( allnames[i], "i" ),
		Insert Into( inames, allnames[i] )

allset = Associative Array( allnames ); // {"name", "age", "sex", "height", "weight"}
iset = Associative Array( inames ); // {"height", "weight"}

allset << Remove( iset ); // the "not i" set...
notinames = allset<<getkeys; // {"age", "name", "sex"}

For( i = 1, i <= N Items( notinames ), i++,
	dt:(notinames[i]) << Set Selected( 1 )
dt << Delete Columns(); // only the "i" names remain


Last Modified: May 18, 2017 7:02 PM