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!