Hola a todos,
Mi objetivo es seleccionar sólo las filas que tienen los valores más comunes (tipo de carácter) en cada columna.
Por ejemplo, mi tabla tiene cuatro columnas: A, B, C y D. Los valores que más aparecen en las columnas A, B, C y D son A1, B2, C3 y D4, respectivamente. ¿Cómo puedo escribir un código JSL que filtre las filas por estos valores y cree una nueva tabla con los datos filtrados? Gracias.
Gracias
Si tuviera datos como este donde (COL -> Mayoría de apariciones) es A -> A1, B -> B2, C -> C1 (en realidad C tiene un empate, ¿cómo deberían manejarse?)

¿Desea conservar únicamente la fila 1, ya que tiene A1, B2 y C1? Y si hubiera más filas con los mismos valores, ¿querría conservarlas todas? ¿O estás buscando algo totalmente diferente, por ejemplo quieres tener una tabla que solo tenga los valores que aparecen con más frecuencia?
Aquí tienes un script que debería ayudarte a resolver tu problema.
Names Default To Here( 1 );
// build an example data table
dt = New Table( "Example",
add rows( 20 ),
New Column( "A",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 40, x = 1,
rand >= 40 & rand <= 60, x = 2,
rand >= 60 & rand <= 80, x = 3,
x = 4
);
"A" || Char( x );
)
),
New Column( "B",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 20, x = 1,
rand >= 20 & rand <= 60, x = 2,
rand >= 60 & rand <= 80, x = 3,
x = 4
);
"B" || Char( x );
)
),
New Column( "C",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 20, x = 1,
rand >= 20 & rand <= 40, x = 2,
rand >= 40 & rand <= 80, x = 3,
x = 4
);
"C" || Char( x );
)
),
New Column( "D",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 20, x = 1,
rand >= 20 & rand <= 40, x = 2,
rand >= 40 & rand <= 60, x = 3,
x = 4
);
"D" || Char( x );
)
)
);
// The JSL below is the code that does the actual work
Data Table( "Example" ) << Stack(
columns( :A, :B, :C, :D</img> ),
Source Label Column( "Column" ),
Stacked Data Column( "Data" ),
Output Table( "Stacked" )
);
dtS = Data Table( "Stacked" ) << Summary(
Group( :Column, :Data ),
Freq( "None" ),
Weight( "None" ),
output table name( "Summary" )
);
dtS << select where( :N Rows[Row()] == col max(:N Rows, :Data));
dtS << new column("Mode", formula(
Col Max(:N Rows, :Column)
));
dtS << select where( :N Rows == :Mode);
dtS << invert row selection << delete rows;
eval(parse(
"dt << Select Where (dt:\!"" || dts:column[1] || "\!"n == dtS:Data[1] );"));
For( i=2,i<=NRows(dtS), i++,
eval(parse(
"dt << Select Where (dt:\!"" || dts:column[i] || "\!"n == dtS:Data[i] , current selection(\!"extend\!"));"));
);
dtFinal = dt << Subset( selected columns(0), selected rows(1), output table("Final"));