Evaluating Col Mean with IterationsHi everyone,
I'm having trouble evaluating a col mean function. As you can see below, the col mean(:age, :list_col_names[i]] doesnt insert the item in the list on the data table. With this current configuration, when I open the formula on the data table I get "Col Mean( :age, list_col_names[i] )" which doesnt correspond to anything on the list_col_names list.
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 />);
on in an iteration
Re: Evaluating Col Mean with IterationsWorks great. Thank you Vince!
Re: Evaluating Col Mean with Iterationsyou can't do :list_col_names[i], You're explicitly stating that you have a column called "list_col_names" and you're pulling the ith row of it.
Try this
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]))
) )
)
)
)
);