おはよう。
JSLコードを使用して、GOOD / BAD行の列から開始して、BAD = 1およびGOOD = Ratio BAD/GOODである新しいWEIGHT COLUMNを作成したいと考えています。
それを素早く行うための JSL はありますか?
前もって感謝します
ジャンパオロ
ここでは、同様のソリューションを 2 つ紹介します。
これは、開いた JSL に新しい列を生成します。
Names Default To Here( 1 );
// Create the sample data table
dt = New Table( "Good Bad Ratio",
Add Rows( 14 ),
New Column( "Good_Bad",
Character,
"Nominal",
Set Values(
{"GOOD", "BAD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD",
"GOOD", "BAD", "BAD", "BAD"}
)
)
);
// Create the new column using a formula for the calculation
dt << New Column( "Weight",
formula(
If( Row() == 1,
TheGoodCount = Col Number( If( :Good_Bad == "GOOD", 1, . ) );
TheBadCount = Col Number( If( :Good_Bad == "BAD", 1, . ) );
Ratio = TheBadCount / TheGoodCount;
);
If(
:Good_Bad == "GOOD", Ratio,
:Good_Bad == "BAD", 1
);
)
);
このバージョンでは、列の式を使用して列の値を作成します。
Names Default To Here( 1 );
// Create the sample data table
dt = New Table( "Good Bad Ratio",
Add Rows( 14 ),
New Column( "Good_Bad",
Character,
"Nominal",
Set Values(
{"GOOD", "BAD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD", "GOOD",
"GOOD", "BAD", "BAD", "BAD"}
)
)
);
// Calculate the Ratio
TheGoodCount = Col Number( If( dt:Good_Bad == "GOOD", 1, . ) );
TheBadCount = Col Number( If( dt:Good_Bad == "BAD", 1, . ) );
Ratio = TheBadCount / TheGoodCount;
// Add the new column and populate it
dt << New Column( "Weight" );
For Each Row(
If(
dt:Good_Bad == "GOOD", dt:Weight = Ratio,
dt:Good_Bad == "BAD", dt:Weight = 1
)
);