cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Uncharted

Choose Language Hide Translation Bar
Craige_Hales
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;
all<<insert(cmy);
all<<insert(bw);
show(all<<getkeys); // {"black", "blue", "cyan", "green", "magenta", "red", "white", "yellow"}
// take two from set
two = associativearray({"magenta","red"});
all<<remove(two);
show(all<<getkeys); //{"black", "blue", "cyan", "green", "white", "yellow"}
// find common colors
rainbow = associativearray({"orange","cyan","green","red","blue"});
all<<intersect(rainbow);
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 Class.jmp" );
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
Comments