Iterazione attraverso due tabelle di dati di dimensioni diverse e confronto per valori corrispondentiCiao,
Ho il seguente problema:
- Ho due tabelle di dati in file jmp separati, ognuno dei quali ha una colonna.
- Una tabella è lunga 8 righe mentre l'altra è lunga 6440 righe.
- Il mio obiettivo è esaminare ciascuno dei valori nella tabella a 8 righe e confrontarli con ogni valore nella tabella a 6440 righe per vedere se corrispondono.
- Mi stavo solo chiedendo come potevo farlo perché voglio scorrere entrambe le tabelle ma hanno dimensioni diverse. Stavo pensando di usare un ciclo for nidificato ma non ne sono troppo sicuro.
Qualsiasi aiuto sarebbe apprezzato.
Re: Iterazione attraverso due tabelle di dati di dimensioni diverse e confronto per valori corrispondentiHo commesso un leggero errore nel mio precedente esempio di pseudo codice,
dtShort:Compare Column[i] > dtLong:Compare Column</CODE></PRE>
<P><SPAN>Deve essere invertito nella logica per funzionare</SPAN></P>
<PRE><CODE class=" language-jsl"> dtLong:Compare Column > dtShort:Compare Column[i]
Ecco un esempio funzionante
Names Default To Here( 1 );
dtLong = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Create the short data table
dtShort = New Table( "Short",
New Column( "Target Age", values( {12, 16} ) ),
New Column( "Match", character, values( {"Teenager", "Young Adult"} ) )
);
// Sort the data for illustration of data not being
// in age order
dtLong << sort( by( :Name ), replace table( 1 ) );
// Create a couple of new columns in the data table
dtLong << New Column( "Kind Of Match", character );
dtLong << New Column( "Count" );
// Process the data
For( i = 1, i <= N Rows( dtShort ), i++,
// Find all rows that match the Where Clause
theRowsFound = dtLong << get rows where( dtLong:Age > dtShort:Target Age[i] );
// If some rows were found process
If( N Rows( theRowsFound ) > 0,
// Set a value in the dtLong data table with one statement
// that sets values in multiple rows
dtLong:Kind Of Match[theRowsFound] = dtShort:Match[i];
// Now set values row by row for individual rows that were found
theCount = 1;
For( k = 1, k <= N Items( theRowsFound ), K++,
dtLong:Count[theRowsFound[k]] = theCount;
theCount = theCount + 1;
);
);
);Re: Iterazione attraverso due tabelle di dati di dimensioni diverse e confronto per valori corrispondentiGrazie per la risposta rapida.
Per la parte seguente:
dtLong : Compare Column
Ti dispiace spiegare come posso accedere a tutti i valori in una colonna senza dover fare riferimento a ciascun pedice/indice della colonna?
Re: Iterazione attraverso due tabelle di dati di dimensioni diverse e confronto per valori corrispondentiEcco come lo tratterei.......
// This is pseudo code, but it will give you an idea of the flow
dtShort = Open( "<YOUR short="" data="https://community.jmp.com/" table="">" );
dtLong = Open( "<YOUR long="" data="https://community.jmp.com/" table="">" );
For( i = 1, i <= N Rows( dtShort ), i++,
theRowsFound = dtLong << get rows where( dtShort:Compare Column[i] > dtLong:Compare Column );
If( N Rows( theRowsFound ) > 0,
// Do your processing
);
);</YOUR></YOUR>
Re: Iterazione attraverso due tabelle di dati di dimensioni diverse e confronto per valori corrispondentiGrazie per la tua risposta.
Come suggeriresti di risolvere il problema se volessi verificare se il valore nella tabella a 8 righe è maggiore rispetto al valore nella tabella a 6440 righe?
Re: Iterazione attraverso due tabelle di dati di dimensioni diverse e confronto per valori corrispondentiCredo che il modo più semplice per farlo sia lasciare che JMP faccia il lavoro per te.Se unisci le tabelle in una nuova tabella, puoi fare in modo che JMP crei una nuova colonna chiamata Match flag, che ti dirà se una corrispondenza è stata trovata o meno
Tabelle==>Unisciti