Is there a a way to input a list of columns as by group variables into column mean/std dev/median?Hi All,
I'm trying to generate a new column to be a mean column of :A by groups specified by :B, :C,
.
Is there a way to do this where :B, :C,
is a list? I'd like this so I can populate it using Col Dialog.
If not, is there a way to break the list into arguments?
The first line below gives me the desired means while the second line gives me the overall mean of :A.
mean= New Column("Mean", Formula(Col Mean(:A, :B, :C,
)));
mean = New Column("Mean", Formula(Col Mean(:A, {:B, :C,
})));
Thanks in Advance.
ScriptingRe: Is there a a way to input a list of columns as by group variables into column mean/std dev/median?Here is an easy way to solve this
Names Default To Here( 1 );
// Open Data Table: big class.jmp
// → Data Table( "big class" )
dt = Open( "$SAMPLE_DATA/big class.jmp" );
colList = {"height", "Sex", "Age"};
Eval(
Substitute(
Expr(
dt << New Column( "Mean",
formula( Col Mean( __one__, __two__, __three__ ) )
)
),
Expr( __one__ ), Parse( ":" || colList[1] ),
Expr( __two__ ), Parse( ":" || colList[2] ),
Expr( __three__ ), Parse( ":" || colList[3] )
)
);Re: Is there a a way to input a list of columns as by group variables into column mean/std dev/median?If you columns in a list with :name format, you can also use this option (idea from Using list of columns in formulas )
Names Default To Here(1);
// Open Data Table: big class.jmp
// → Data Table( "big class" )
dt = Open("$SAMPLE_DATA/big class.jmp");
col_list = {:height, :Sex, :Age};
formula_expr = Name Expr(Substitute(col_list, Expr(List()), Expr(Col Mean())));
Eval(EvalExpr(
dt << New Column("Mean", Formula(Expr(formula_expr)));
));
For using Eval, Eval Expr, Expr, Substitute... see Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute
Re: Is there a a way to input a list of columns as by group variables into column mean/std dev/median?Thanks Jim, would there be a way to do this if the size of the list was undetermined?