JMP 社群您好,
我產生了多個儲存在列中的預測公式,我需要提取參數來評估公式中哪些變數是常見的。
當我呼叫 dt:Column X << 取得公式時,輸出為不是可以與標準模式提取函數(例如,Words ()、Munger ()...)一起使用的字串或列表。
問題:
- 我是否使用正確的函數透過使用 << 來取得公式來收集公式參數?
- 如果沒有,什麼是更適合的功能?
- 如果是,是否有技巧將 << Get 公式輸出轉換為字串、列表或矩陣?
感謝您的協助。
最好的,
TS
我將在這裡記錄另一種方法。 (謝謝@Byron_JMP有關此的 Arg() 教程)
您可以透過 Arg() 指令來取得可以輕鬆使用的清單形式的參數。 我還在下面放置了一個函數,該函數將列公式的參數作為關聯數組傳回。
// For a given column, col, in a data table, dt, you can get the formula column property with a message:
formula = dt:Col << Get Formula;
// the first argument of which is the parameters list which can be extracted using Arg()
params = Arg(formula, 1);
// from there you can index down to get the parameter / value pair
parameterName1 = Arg(params[1],1);
parameterValue1 = Arg(params[1],2);
以及將公式參數作為關聯數組傳回的函數
// This function expects a column reference
formulaParameters = Function( {colref},
{default local},
plist = Arg( colref << Get Formula, 1 );
keys = {};
values = {};
For Each( {value, index}, plist,
Insert Into( keys, Arg( value, 1 ) );
Insert Into( values, Arg( value, 2 ) );
);
parameters = Associative Array( keys, values );
);
// Usage example:
dt = Current Data Table();
columnWithParameters = dt:Col1 << Get Column Reference();
parameterAArray = formulaParameters( columnWithParameters );如果感興趣的是公式內的變數名稱,直接使用公式表達式可能會更容易。 這是一個從公式中提取唯一符號名稱的範例。
dt = open("$sample_data/Reliability/Locomotive.jmp");
ex = column(dt, 3)<<GETFORMULA></GETFORMULA>由於相當“老派”,我通過將公式作為字串檢索來處理它
Names Default To Here( 1 );
dt = Current Data Table();
x = Char( dt:predicted height << get formula );