创建新列,并将公式保存为脚本中的变量我正在使用一个脚本从我现有的一些数据中提取一个预测公式,然后使用替换修改了该公式,现在想用修改后的公式创建一个新列。我觉得这很容易,但是当我尝试编写脚本时,保存为变量的公式无法被识别。任何帮助都将不胜感激,如果您也需要更多信息,请告诉我。
//Script that just shows saving the formula as a variable fm and modifying the variable using substitute to fm2
fm = report(obj1)[OutlineBox("Polynomial ?")][TextEditBox(1)] << get text;
//get the string to the right of the equal sign and convert the string to an expression using Parse()
fm = Parse(Trim(word(2, fm, "=")));
fm2 = Substitute(NameExpr(fm), EvalExpr(LnTime2), EvalExpr(log(Time2)));
//Script to create a new column with the fm2 formula that does not work
dt << New Column( "Predicted", Numeric, Formula (fm2));
//这是在脚本中打印 fm2 时在日志中返回的内容
打印(fm2);
(-0.270568) + 0.0352458 * Log(时间2) - 0.0331127 * (Log(时间2) - 7.22484) ^ 2 + 0.0046766 * (Log(时间2) - 7.22484) ^ 3 + 0.0075752 * (Log(时间2) - 7.22484) ^ 4 + 0.0012501 * (Log(时间2) - 7.22484) ^ 5 + 0.000026534 * (Log(时间2) - 7.22484) ^ 6
高级统计建模消费者和市场研究内容组织数据混合和清理数据探索与可视化大规模定制质量与工艺工程分享和交流结果回复:使用在脚本中保存为变量的公式创建新列试试这个:
Eval(
Substitute(
Expr( dt << New Column( "Predicted", Numeric, Formula ( fff ) ) ),
Expr( fff ), Name Expr( fm2 )
)
);
回复:使用在脚本中保存为变量的公式创建新列我会将公式保留为字符串,在其中替换,添加“:”以告知 JMP 您正在处理一列,然后使用
评估(解析())
执行它。这是一个简单的例子
names default to here(1);
dt=current data table();
fm="height";
fm2 = substitute(fm, expr("height"), "log(:height)");
eval(parse("dt << new column (\!"predicted\!",numeric,formula(" || fm2 || "));"));回复:使用在脚本中保存为变量的公式创建新列感谢您提示将公式保留为字符串并添加":" 让 JMP 知道是否是一列。 我无法让 eval(parse()) 工作,我不确定为什么这里也需要双引号。
回复:使用在脚本中保存为变量的公式创建新列谢谢!