Loop to set a normalization formula for several columnsHi community,
I'm trying to write a JSL script to set a normalization formula with dynamic column reference.
What's wrong here?
"Mean(M4_pop)" & "Std Dev(M4_pop)" are fix columns that are to be used for the normalization.
dt = Current Data Table();
numCols = dt << Get Column Names( Numeric, "String" );
For( i = 1, i <= N Items( numCols ), i++,
colName = numCols[i];
normColName = colName || "_norm";
dt << New Column(
normColName,
Numeric,
Continuous,
Formula( (colName- :"Mean(M4_pop)"n) / :"Std Dev(M4_pop)"n)
);
);
Automation and ScriptingRe: Loop to set a normalization formula for several columnsYou will have to evaluate colName to the formula
Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute
Re: Loop to set a normalization formula for several columnsHi David,
there might be prettier solutions but this is one way to make it work:
dt = Current Data Table();
numCols = dt << Get Column Names( Numeric, "String" );
For( i = 1, i <= N Items( numCols ), i++,
colName = numCols[i];
mean = "Mean(M4_pop)";
std = "Std Dev(M4_pop)";
normColName = colName || "_norm";
dt << New Column(
normColName,
Numeric,
Continuous,
Formula( (as column(colName)- as column (mean)) / as column(Std))
);
);
Cheers,
Jonas
Re: Loop to set a normalization formula for several columnsHi Jonas,
thanks for your response. Small changes that led to sucess