cómo hacer un subconjunto de una tabla y anexar datos de bucleHola,
Tengo un conjunto de datos, (ver adjunto). Quiero verificar cada fila de una columna (con un cierto criterio) y luego aislar las filas que no cumplen con ese criterio y agruparlas en una nueva tabla de datos. Quiero poder repetir esto para varias columnas (donde cada una tiene sus propios criterios) y continuar agregando a esta tabla de subconjunto que originalmente creé. Estoy teniendo algunos problemas con esto y esperaba que alguien pudiera ayudar.
esto es lo que estaba haciendo:
path = "xxxxxxx/";
data_table = Open( path || "Sample Data.jmp" );
Sub_Table = New Table( "Rejected Parts Table", invisible );
New_table = data_table;
For( k = 1, k < N Col( New_table ), k++,
Print( k );
New_table << select where( Column( 1 + k )[] >= 0.2 | Column( 1 + k )[] <= 0.02 );
alp = New_table << Subset( Selected Rows, output table name( "subset" ) );
alp << Concatenate( Sub_Table, output table name( "Rejected Parts Table" ) ) <<
Save( path || "Rejected Parts.jmp" );
Close( alp );
New_table << delete rows();
);
Re: cómo hacer un subconjunto de una tabla y anexar datos de bucleUn enfoque alternativo que utiliza los mismos criterios para todas las columnas:
dt = Data Table( "Sample Data.jmp" );
r = Loc( V Sum( Transpose( !(0.02 < dt << get as matrix < 0.2) ) ) );
dt << Subset( rows( r ), output table name( "Rejected Parts Table" ) );
dt << delete rows( r );
Un poco más complicado cuando cada columna tiene sus propios criterios, por ejemplo:
dt = Data Table( "Sample Data.jmp" );
upper = [0.2 0.3 0.2 0.4 0.2];
lower = [0.02 0.03 0.02 0.04 0.02];
r = Loc( V Sum( Transpose( !(Repeat( lower, N Row( dt ) ) < dt << get as matrix < Repeat( upper, N Row( dt ) )) ) ) );
dt << Subset( rows( r ), output table name( "Rejected Parts Table" ) );
dt << delete rows( r );
Re: cómo hacer un subconjunto de una tabla y anexar datos de bucleEste fue un poco complicado. La solución principal es utilizar AS COLUMN en su declaración de selección. Cambié la lógica para usar las filas de obtención donde y construir una lista de filas para subcontratar / eliminar. ¡La función get_unique_values es cortesía de este foro!
get_unique_values = Function( {in_list},
{Default Local},
tmp = [=> 0];
Insert Into( tmp, in_list );
tmp << get keys;
);
path = "c:\temp\";
New_table = Open( path || "Sample Data.jmp" );
all_selected_rows = [];
For( k = 1, k < N Col( New_table ), k++,
Print( k );
selected_rows = new_table << get rows where( As Column( 1 + k ) >= .2 | As Column( 1 + k ) <= .02 );
// Append the rows we just found to the master list
If( N Rows( selected_rows ) > 0,
all_selected_rows = all_selected_rows |/ selected_rows
);
);
// Convert matrix to a list and get unique values
all_selected_list = get_unique_values( As List( all_selected_rows ) );
alp = New_table << Subset( rows( all_selected_list ), output table name( "Rejected Parts Table" ) );
alp << Save( path || "Rejected Parts.jmp" );
Close( alp );
New_table << delete rows( all_selected_list );