cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
vistacc
Level III

table is empty when being referenced

 Hi all!

I tried to select a column in a generated data table and transform that column into a new data table. Following is my code:

 

//part 1: generate a data table
ret = New Table( title, Add Rows (rowNum), New Column( "P", Expression, "Continuous", Formula( pmatrix ) ), New Column( "X(n)", Expression, "None", Formula( If( Row() == 1, init_state, Lag( :Name( "X(n)" ), 1 ) * :P ) ), Set Selected, ), New Column( "steady state", Expression, "None", Formula( :Name( "X(n)" ) - Lag( :Name( "X(n)" ) ) == zeros ), ), New Column( "States", Character, Values( names ) ), ); // part 2: select column X(n) and transform it into a new table mat = Column(ret,"X(n)")[1]; show(mat); For(i = 2, i <= N Rows(ret), i++, V Concat To(mat,Column(ret,"X(n)")[i]); ); table = As Table(mat); names = Column(ret, "States") << get values; For(i = 1, i <= N Col(table), i++, Column(i) << Set Name( names[i] ); );

 When I tested the two parts seperately by saving the result table in part 1 and then running part 2, it works. But I don't want to save the table in part 1 everytime before running part 2 so I put them together. However, the merged script doesn't work. In this case, the table returned by part 2 only has missing values (Empty()).

 

I add "show(mat);" in the script to see what happened and it shows "mat = Empty();" in the log. The expected value of mat should be a vector as in each row of Column X(n) of the data table in part 1.

 

I don't know what went wrong. Any help would be appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: table is empty when being referenced

wait(n) is not the best solution; it is hard to know if n is big enough. JMP evaluates the table formulas in the background. The best way to make sure they have evaluated is

ret << RunFormulas;

after building the table. It will evaluate the table's formulas faster than waiting for them.

Craige

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: table is empty when being referenced

I do not see the reference to the variable "ret".  In the second half of the code, ret is used, but not in the 1st half......

Jim
vistacc
Level III

Re: table is empty when being referenced

Sorry. Don't know why something went wrong with the format. The first line of the script is commented...

	ret = New Table( 
		Add Rows (rownum),
		New Column( "P", Expression, "Continuous", Formula( ptable << get as matrix ) ),
		New Column( "X(n)",
			Expression,
			"None",
			Formula( If( Row() == 1, init_state, Lag( :Name( "X(n)" ), 1 ) * :P ) ),
			Set Selected,

		),
		New Column( "steady state",
			Expression,
			"None",
			Formula( :Name( "X(n)" ) - Lag( :Name( "X(n)" ) ) == zeros ),

		),
		New Column( "States", Character, Values( names ) ),

	);

 

 

vistacc
Level III

Re: table is empty when being referenced

I found a solution that can solve my problem: adding "wait(1)" between the two parts will work. (reference:

https://community.jmp.com/t5/Discussions/Add-new-column-with-formula-to-data-table-at-certain-positi...

but I don't understand why this works... Is there any other way that can also address this problem?

 

Craige_Hales
Super User

Re: table is empty when being referenced

wait(n) is not the best solution; it is hard to know if n is big enough. JMP evaluates the table formulas in the background. The best way to make sure they have evaluated is

ret << RunFormulas;

after building the table. It will evaluate the table's formulas faster than waiting for them.

Craige
Craige_Hales
Super User

Re: table is empty when being referenced

And thanks for the report; the column function will do the <<runFormulas internally in JMP 15.

Craige
vistacc
Level III

Re: table is empty when being referenced

Thank you for the reply!