Define Column Formula from User InputHi,
I am trying to define a new column formula from user input. I have tried different combinations of Eval(), Eval Insert(), and Parse() without success. Input can either be columns or lists of columns, plus a scalar. Below is a minimal example. Any suggestions? I am using JMP14, but I hope the solution will work for JMP12 and above.
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Define new column.
dt << New Column( "Mean for Each Age and Sex Group",
Formula( Col Mean( :height, :age, :sex ) )
);
// Define user input.
a = 2;
c1 = :height;
c2 = {:age, :sex};
// Define new column from user input.
dt << New Column( "Mean for Each Age and Sex Group 2",
Formula( Col Mean( a * c1, c2 ) )
);Re: Define Column Formula from User InputI am not totally sure what formula you want in the newly created column from user input, but take a look at this JSL Cookbook article, it gives examples of several different methods of constructing your new column formula.
Re: Define Column Formula from User InputThanks! Very useful page.
Re: Define Column Formula from User InputWith help from @ih's input, here is a solution for anyone interested...
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Define user input.
a = 2;
c1 = Column( "height" );
c2 = {:age, :sex};
// Define new column from user input.
input = Concat( "As Column( \!"", c1 << Get Name, "\!" )" );
If( N Items( c2 ) > 0,
For( i = 1, i <= N Items( c2 ), i++,
input = Insert( input, Concat( ", ", "As Column( \!"", Char( c2[i] ), "\!" )" ) )
)
);
Eval( Parse( Eval Insert( "dt << New Column( \!"Mean for Each Age and Sex Group 2\!", Formula( ^a^ * Col Mean( ^input^ ) ) )" ) ) );