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 );