循环设置多列的规范化公式大家好,
我正在尝试编写一个 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))
);
);
干杯,
乔纳斯
回复:循环为多列设置规范化公式嗨,乔纳斯,
谢谢你的回复。小小的改变带来了成功:)