Re: How to use formula with different columns in a scriptYou are very close. All you need to do, is to create a second value to substitute on, and to reference the i+1 column for it's substitution
names default to here(2);
dt=open("$SAMPLE_DATA/blood pressure.jmp");
numericColNames = dt << get column names( string, numeric );
For( i = 1, i <= N Items( numericColNames ) - 1, i += 2,
Eval(
Substitute(
Expr(
New Column( Char( numericColNames[i] ) || "_Stand",
Numeric,
Continuous,
Formula( (__col1__) / (__col2__) )
)
),
Expr( __col1__ ), Parse( ":" || numericColNames[i] ),
Expr( __col2__ ), Parse( ":" || numericColNames[i+1] )
)
)
);
How to use formula with different columns in a scriptHi.
I have a data table with numeric columns and I intend to create new columns with the result of dividing column 1 by column 2, column 3 divided by column 4 and so on.
I have this script but my problem is that I don't know how to indicate column 2 in the dividend.
numericColNames = dt << get column names( string, numeric );
For( i = 1, i <= N Items( numericColNames ) - 1, i += 2,
Eval(
Substitute(
Expr(
New Column( Char( numericColNames[i] ) || "_Stand",
Numeric,
Continuous,
Formula( (__col__) / (__col__) )
)
),
Expr( __col__ ), Parse( ":" || numericColNames[i] )
)
)
);ScriptingRe: How to use formula with different columns in a scriptThank you very much Mr. Nelson. It is what I was looking for.