cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

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