使用包含列名称和公式的 for 循环创建新列我正在尝试从现有表创建一个拆分表,并将新列添加到拆分表中,每个新列都具有基于拆分列的公式。 然而,代码创建了新列,但给了我“公式评估错误”
dt2 = Current Data Table();
// Create the split data table
dt2 = dt << Split(
Split By( :S ),
Split(
:Name( "Median(data)" )
),
Group( :L, :m, :C, :P, :z, :x ),
Remaining Columns( Drop All ),
Sort by Column Property
);
colname = {"B","C"};
colby = {"A","B"};
// Add new columns to the split data table
For( i = 1, i <= N Items( colname ), i++,
dt2 << New Column( colname[i]||"/"||colby[i],
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( column(colname[i]) / column(colby[i]) )
););自动化和脚本编写回复:使用带有列名和公式的 for 循环创建新列JMP 公式定义在定义时不会计算,仅在运行时计算。因此,该公式需要以完全定义的形式呈现给 JMP。
Column( colname[i] ) / Column( colby[i] )
需要提交给 JMP 作为
Column( "B" ) / Column( "A" )
使用替换功能可以根据需要扩展代码
// Add new columns to the split data table
For( i = 1, i <= N Items( colname ), i++,
Eval(
Substitute(
Expr(
dt2 << New Column( colname[i] || "/" || colby[i],
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula( Column( __colname__ ) / Column( __colby__ ) )
)
),
Expr( __colname__ ), colname[i],
Expr( __colby__ ), colby[i]
)
)
);回复:使用带有列名和公式的 for 循环创建新列我仍然遇到同样的错误,如下
Column B/A Formula Interrupted
Cannot convert argument to a number [or matrix] 1 times At rows: 2 Operation: Divide, Column( "B" ) / /*###*/Column( "A" ) /*###*/
Formula evaluation errors have been ignored
Column C/B Formula Interrupted
Cannot convert argument to a number [or matrix] 1 times At rows: 2 Operation: Divide, Column( "C" ) / /*###*/Column( "B" ) /*###*/
Formula evaluation errors have been ignored
回复:使用带有列名和公式的 for 循环创建新列尝试将 Column() 函数更改为 As Column() 函数
回复:使用带有列名和公式的 for 循环创建新列那行得通,谢谢!