I am trying to create new columns in a data table, each new column is the Z-score of an existing column. Here is what I have
Colnames_1st = dt_zscore3 << Get Column Names();
nlist = N Items(Colnames_1st);
for (i=5, i <=10, i++,
var1 = Column(Colnames_1st);
mean = Col Mean(var1);
stdev = Col Std Dev(var1);
namevar = char(Colnames_1st);
New Column("Zscore " || namevar,
Numeric, Continuous,
Format("Best", 12),
Formula((((var1[]) - mean )/stdev )));
);
The code creates the 6 new columns and names them correctly.
But when it goes to fill in the values in all the columns, it does not do it correctly.
All the columns end up with the same value in each row. It looks to me like it
is creating the columns, but then waits til the for loop is over to calculate the
values that go in each row in all the columns, so it uses the last value of all
the variables for all the columns, instead of calculating the formula for each
column using the values that should be used by that column.
I am really stuck. I have tried all sorts of things but can't get over this hurdle.
Any help would be much appreciated.