좋은 아침이에요.
JSL 코드를 사용하여 GOOD/BAD 행이 있는 열에서 시작하여 BAD =1이고 GOOD = BAD/GOOD 비율인 새 WEIGHT COLUMN을 만들고 싶습니다.
빨리 할 수 있는 JSL이 있나요?
미리 감사드립니다
잔파올로
다음은 두 가지 유사한 솔루션입니다.
이것은 공개 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
);
)
);
이 버전은 열 수식을 사용하여 Weight 열의 값을 생성합니다.
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
)
);