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!
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.
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......
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 ) ),
);
I found a solution that can solve my problem: adding "wait(1)" between the two parts will work. (reference:
but I don't understand why this works... Is there any other way that can also address this problem?
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.
And thanks for the report; the column function will do the <<runFormulas internally in JMP 15.