Buen día.
Usando código JSL, a partir de una columna con filas BUENO/MALO, me gustaría crear una nueva COLUMNA DE PESO, donde MALO = 1 y BUENO = Relación MALO/BUENO.
¿Existe JSL para hacerlo rápidamente?
gracias de antemano
Gianpaolo
Genial Jim, muchas gracias.
Adaptaré tu código a mi trabajo.
Aquí hay dos soluciones similares.
Este genera la nueva columna en JSL abierto
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
);
)
);
Esta versión utiliza una fórmula de columna para crear los valores para la columna Peso
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
)
);