この例では、If文の計算式を含んだ列を、データテーブルに追加します。「Create a Formula Column.jsl」は、「Big Class.jmp」サンプルデータにおいて、「年齢」(Age)列に対するIf文の結果を含む列を、新規に作成します(図17.3)。
/* Scenario:
How do you create a formula column that combines conditional expressions
with value comparisons? This script shows how to create a new formula
column that evaluates ages in Big Class.jmp and returns the conditional
result in the new column.*/
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
/* Create a new character column for the formula.
Insert "early" in the new column if the age is less than or
equal to 12.Insert "mid" if the age is less than or equal to
15 but greater than 12.For ages greater than 15, insert "late".
*/
dt << New Column( "Adolescent Phase",
Character,
Formula(
If( :age <= 12, "early",
12 < :age <= 15, "mid",
"late"
)
)
);
図17.3 計算式内の条件式