我遇到了類似的問題。 我在一列中執行除法運算,然後需要轉置表。當我嘗試執行此操作時遇到問題。
dtIn << New Column("Max Size ",Character,format("best",8),Formula(
:Name("Max Size") = (2500/:Min Size))
);
//check for empty columns and delete if any
dt = Current Data Table();
names = dt << Get Column Names();
dt1 = dt << Missing Data Pattern(columns(Eval(names)), invisible);
n = N Row(dt1);
For(i = N Col(dt), i >= 1, i--,
If(Col Sum(Column(dt1, i + 3)) < n,
Remove From(names, i)
)
);
Try(dt << delete columns(names));
Close(dt1, nosave);
//Get all coulmn names
allcolnames = dt << get column names(string);
show(allcolnames);
for (i = 1, i <= nitems(allcolnames), i++,
column(dt, allcolnames[i]) << data type(Character,"Nominal");
);
但由於公式而出現錯誤 -
Cannot convert argument to a number [or matrix] 1 times At rows: 2 Operation: Divide, 2500 / /*###*/:Min Size/*###*/
Formula evaluation errors have been ignored
你的公式涉及除法。 此計算需要數字數據列。 您的結果是為具有字符數據類型的新列設置的。 如果這是您想要的,請將除法包裝在 Char() 函數內以滿足數據類型。
要先創建匯總表,然後向其中添加公式列,請在創建表時保存對錶的引用:
//Save reference to the newly created summary table.
dt = Data Table( "Thickness" ) << Summary( Group( :Bar ), N, Mean( :Thickness 01 ) );
//Send a message to the new table to create the new column.
dt << New Column( "New formula column",
Character,
Formula(
If( :Name( "Mean(Thickness 01)" ) > 0.04,
"normal",
"thin"
)
)
);