建立新列,並將公式儲存為腳本中的變量我正在使用腳本從我擁有的一些數據中提取預測公式,然後使用替換修改該公式,現在想使用修改後的公式創建一個新列。我認為這很容易,但是當我嘗試編寫腳本時,保存為變數的公式無法被識別。任何幫助都將不勝感激,如果您也需要更多信息,請告訴我。
//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) ^ 375 7.22484) ^ 4 + 0.0012501 * (Log(時間2) - 7.22484) ^ 5 + 0.000026534 * (Log(時間2) - 7.22484) ^ 6
進階統計建模消費者與市場研究內容組織資料混合與清理數據探索與視覺化大規模客製化品質與工藝工程分享和交流成果回复:使用在腳本中保存為變量的公式創建新列謝謝你!
回复:使用在腳本中保存為變量的公式創建新列感謝提示將公式保留為字符串並添加“:”讓 JMP 知道它是否是一列。 我無法讓 eval(parse()) 工作,我不確定為什麼這裡也需要雙引號。
回复:使用在腳本中保存為變量的公式創建新列我會將公式保留為一個字符串,在其中替換,添加一個“:”讓 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 || "));"));回复:使用在腳本中保存為變量的公式創建新列試試這個:
Eval(
Substitute(
Expr( dt << New Column( "Predicted", Numeric, Formula ( fff ) ) ),
Expr( fff ), Name Expr( fm2 )
)
);