cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP Security Notice: CVE-2026-109618 and CVE-2026-109619

    JMP promptly initiated a review of its products, services, and relevant infrastructure for exposure to CVE-2026-109618 and CVE-2026-109619.

    Our assessment of JMP products has not identified exposure to these vulnerabilities. Where remediation was required within supporting environments, appropriate security updates and controls have been applied and validated.

    We have identified no evidence of successful exploitation or unauthorized access to JMP systems or customer information associated with these vulnerabilities.

    JMP continues to monitor the issue and relevant vendor guidance. No action is required by JMP customers at this time.

  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.

Discussions

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

Append matrices from a loop

I am trying to generate a matrix with the following scripts and have a few questions:

1. in order to correctly get "row" do I need to first sort the fruit column? Is there a Random formula to pick just one number out of "r"?

2. I need the final "run" matrix with the furitName info (the i variable) and be just one matrix. The current script I had would generate 3 run matrices (depending on the N Items(fruitName))

3. Once all run matrices are concatenated in one, is there a way to output the matrix to a data table? 

 

TIA!

 

 

Names Default To Here( 1 );
dt = Current Data Table();
Summarize( dt, fruitName = by( :fruit ) );
For( i = 1, i <= N Items( fruitName ), i++,
	r = dt << get rows where( :fruit == fruitName[i] );
	row = Random Integer( Max( r ) - Min( r ) );
/*show(r);
show(row);*/
	runTime = 5;
	run = [](0, 2);
	For( j = 1, j <= runTime, j++,
		row = Random Integer( Max( r ) - Min( r ) );
		run |/= Matrix( {{j, dt:name( "price hi" )[row] - dt:price lo[row]}} );
	);
	Show( run );
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Append matrices from a loop

Here are a couple of ways to do what I think you are looking for

Names Default To Here( 1 );
dt = Current Data Table();
Summarize( dt, fruitName = by( :fruit ) );
runTime = 5;
run = [](0, 2);
fruitList ={};
For( i = 1, i <= N Items( fruitName ), i++,
	r = dt << get rows where( :fruit == fruitName[i] );
	
	For( j = 1, j <= runTime, j++,
		insert into(fruitList, fruitName[i]);
		row = r[Random Integer( nrows(r))];

		run |/= Matrix( {{j, dt:name( "price hi" )[row] - dt:price lo[row]}} );
	);
);

dtNew = New Table("Random",
	add rows(n rows(run)),
	new column("Fruit", character,set each value(fruitList[Row()])),
	new column("Delta", set each value(run[row(),2]))
);

// or

dtNew2 = dt << Subset(
	Sample Size( runTime ),
	Selected columns only( 0 ),
	Stratify( :fruit )
);
dtNew2 << New Column( "Delta", set each value( :price hi - :price lo ) );
dtNew2 << delete columns( {"price hi", "price lo"} );
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Append matrices from a loop

Here are a couple of ways to do what I think you are looking for

Names Default To Here( 1 );
dt = Current Data Table();
Summarize( dt, fruitName = by( :fruit ) );
runTime = 5;
run = [](0, 2);
fruitList ={};
For( i = 1, i <= N Items( fruitName ), i++,
	r = dt << get rows where( :fruit == fruitName[i] );
	
	For( j = 1, j <= runTime, j++,
		insert into(fruitList, fruitName[i]);
		row = r[Random Integer( nrows(r))];

		run |/= Matrix( {{j, dt:name( "price hi" )[row] - dt:price lo[row]}} );
	);
);

dtNew = New Table("Random",
	add rows(n rows(run)),
	new column("Fruit", character,set each value(fruitList[Row()])),
	new column("Delta", set each value(run[row(),2]))
);

// or

dtNew2 = dt << Subset(
	Sample Size( runTime ),
	Selected columns only( 0 ),
	Stratify( :fruit )
);
dtNew2 << New Column( "Delta", set each value( :price hi - :price lo ) );
dtNew2 << delete columns( {"price hi", "price lo"} );
Jim

Re: Append matrices from a loop

This function might be useful.

 

matrix.PNG

Recommended Articles