cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • 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!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

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

Associative Array - splitting keys

Hi,

 

I've a data table, looks something like this. I want to split each test and assign % values.

 

Jackie__0-1691089344080.png

 

I am trying to create an Associative Array and allocate values to each tests but the results are incorrect. I am not sure what I missed

Jackie__1-1691089533947.png

 

The final associative array should contain the following.

new_aa = [" Currents_A" => 0.003 " Currents_B" => 0.003, " Currents_C" => 0.003, "Volts_A" => 0.003, "Votls_B" => 0.003, "Volts_1" => 0.002,..................., "Currents_0" => 0.001] 

Here's the jsl code. Any suggestions

Names Default To Here( 1 );
dt = Data Table( "dt" );
aa = Associative Array( Column( dt, 1 ) << get values, Column( dt, 3 ) << get values );

fail_test = fa << Get Keys;


split_tests = {};
For Each( {test, index}, fail_test,
	Insert Into( split_tests, Words( test, "," ) )

);
For( i = 1, i <= N Items( split_tests ), i++,
	new_aa = Associative Array( split_tests, If( Contains( aa, split_tests[i] ), aa[split_tests[i]] ) )
	
);
show(new_aa)
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Associative Array - splitting keys

Here is what I would do to get the Associative Array you are looking for

Names Default To Here( 1 );
dt = Data Table( "dt" );

// Get all columns
allOrigColumnsList = dt << get column names( string );

// Move individual elements of the column, to individual columns
dt << Text To Columns( delimiter( "," ), columns( :paretotop20 ) );

// Find all new columns
newColList = dt << get column names( string );
For( i = N Items( newColList ), i >= 1, i--,
	If( Contains( allOrigColumnsList,
		newColList[i]),
		Remove From( newColList, i, 1 )
	)
);
dtStack = Data Table( "dt" ) << Stack(
	columns( eval(newColList) ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" ),
	"Non-stacked columns"n( Keep( :"% of Total"n ) ),
	Output Table( "Untitled 60.jmp" )
);
dtStack << select where(:Data == "" );
dtStack << delete rows;

aa = Associative Array( Column( dtStack, 3 ) << get values, Column( dtStack, 1 ) << get values );
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Associative Array - splitting keys

Here is what I would do to get the Associative Array you are looking for

Names Default To Here( 1 );
dt = Data Table( "dt" );

// Get all columns
allOrigColumnsList = dt << get column names( string );

// Move individual elements of the column, to individual columns
dt << Text To Columns( delimiter( "," ), columns( :paretotop20 ) );

// Find all new columns
newColList = dt << get column names( string );
For( i = N Items( newColList ), i >= 1, i--,
	If( Contains( allOrigColumnsList,
		newColList[i]),
		Remove From( newColList, i, 1 )
	)
);
dtStack = Data Table( "dt" ) << Stack(
	columns( eval(newColList) ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" ),
	"Non-stacked columns"n( Keep( :"% of Total"n ) ),
	Output Table( "Untitled 60.jmp" )
);
dtStack << select where(:Data == "" );
dtStack << delete rows;

aa = Associative Array( Column( dtStack, 3 ) << get values, Column( dtStack, 1 ) << get values );
Jim
Jackie_
Level VI

Re: Associative Array - splitting keys

Thanks, Jim!

Recommended Articles