Bonjour.
en utilisant le code JSL, à partir d'une colonne avec des lignes BON/MAUVAIS, je voudrais créer une nouvelle COLONNE DE POIDS, où MAUVAIS =1 et BON = Rapport MAUVAIS/BON.
Il y a du JSL pour le faire rapidement ?
Merci d'avance
Gianpaolo
Super Jim, merci beaucoup.
j'adapterai ton code à mon travail
Voici deux solutions similaires.
Celui-ci génère la nouvelle colonne en JSL ouvert
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
);
)
);
Cette version utilise une formule de colonne pour créer les valeurs de la colonne Poids
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
)
);