用迭代評估 Col Mean大家好,
我在評估 col mean 函數時遇到問題。 如下所示,col mean(:age, :list_col_names[i]] 不會將項目插入數據表的列表中。 使用當前配置,當我打開數據表上的公式時,我得到“Col Mean( :age, list_col_names[i] )”,它與 list_col_names 列表中的任何內容都不對應。
list_col_names = fdt << getColumnNames( "String" );
For( j = N Items( list_col_names ), j > 0, j--,
If( Left( list_col_names[j], 2 ) != "10",
Remove From( list_col_names, j )
)
);
For( i = 1, i <= N Items( list_col_names ), i++,<BR /> fdt << New Column( list_col_names[i] || "_age", Numeric, Formula( Col Mean( :age, :list_col_names[i] ) ) ) <BR />);
在迭代中
回复:用迭代評估 Col Mean效果很好。 謝謝文斯!
回复:用迭代評估 Col Mean你不能這樣做:list_col_names[i],你明確聲明你有一個名為“list_col_names”的列並且你正在拉它的第 i 行。
嘗試這個
Names Default to here(1);
fdt = open("$SAMPLE_DATA\Big Class.jmp");
list_col_names = {"sex", "name"};
For( i = 1, i <= N Items( list_col_names ), i++,
//this is just it doesn't keep the variable
//in the table because i will change and then your column name will change
Eval(
EvalExpr(
fdt << New Column( list_col_names[i] || "_age",
Numeric,
Formula( Col Mean( :age,
//replaces the string column name with an actual column
Expr(Column(fdt, list_col_names[i]))
) )
)
)
)
);