循環設定多列的規範化公式大家好,
我正在嘗試編寫一個 JSL 腳本來設定具有動態列引用的規範化公式。
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)
);
);
自動化和腳本回覆:循環為多列設定規範化公式您必須根據公式計算 colName
使用 Eval Insert、Eval Expr、Parse 和 Substitute 將一個表達式插入另一個表達式
回覆:循環為多列設定規範化公式嗨,大衛,
可能有更漂亮的解決方案,但這是使其發揮作用的一種方法:
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))
);
);
乾杯,
喬納斯
回覆:循環為多列設定規範化公式嗨,喬納斯,
謝謝你的回覆。帶來成功的小改變:)