Calcoli tra righe in base alle condizioniCiao, sono nuovo nello scripting JMP, ma un po' abituato al linguaggio Python. Sto cercando di ottenere quanto segue con la mia tabella di test fittizia qui sotto:
1) Scorrere tutte le righe (sia prima che dopo la riga) ed eseguire calcoli solo su quelle righe in cui Cuvette == 11, nelle righe rimanenti in cui Cuvette != 11 l'"Output" può essere impostato su NA o qualsiasi altro valore.
2) Il calcolo stesso avviene tra due righe separate. Nelle righe con Cuvette == 11, la cella da 850 nm della riga deve essere divisa con la cella da 250 nm della riga che soddisfa due condizioni:
a) Cuvetta == 12
b) Il valore Pass deve corrispondere tra le righe, ad esempio il valore Pass per la cuvetta 11 == il valore Pass per la cuvetta 12
| Passaggio |
850 nm |
250 nm |
Cuvetta |
Produzione |
| 1 |
100 |
200 |
11 |
100/500 = 0,2 |
| 2 |
400 |
500 |
11 |
400 / 400 = 1 |
| 3 |
300 |
100 |
11 |
300 / 900 = 0,33 |
| 1 |
700 |
500 |
12 |
QUELLO |
| 2 |
200 |
400 |
12 |
QUELLO |
| 3 |
400 |
900 |
12 |
QUELLO |
| 1 |
400 |
800 |
13 |
QUELLO |
| 2 |
500 |
700 |
13 |
QUELLO |
| 3 |
300 |
700 |
13 |
QUELLO |
Automazione e scriptingAnalisi e modellazione dei dati di baseRe: Calcoli tra righe in base alle condizioniPer fare ciò in stile JMP, in genere dovresti dividere i dati e poi eseguire il calcolo ( JMP non è un foglio di calcolo ), quindi riunirli o continuare con i dati divisi.
Ma puoi anche usare JSL o Formula per fare questo calcolo, ma prima considera l'opzione di suddivisione.
Re: Calcoli tra righe in base alle condizioniBenvenuti nella Community.
Ecco un esempio di come affronterei il tuo problema

Names Default To Here( 1 );
dt = Current Data Table();
// Separate out the Cuvette==12 rows into a separate data table
// and then join the Pass==Pass rows to the Cuvette==11 rows
// Then calculate the Output column
// Select the Cuvette==12 rows
dt << Select Where( :Cuvette == 12 );
// Create a new subsetted data table with those rows
dt12 = dt << Subset( Selected Rows( 1 ), columns( :Pass, :"250 nm"n ) );
// Change 250 nm column name so when joined back to original table
// it will have a unique column name
dt12:"250 nm"n << Set Name( "Divisor" );
// For alignment reasons, add a new column called Cuvette and set
// it equal to 11
dt12 << New Column( "Cuvette", Set Each Value( 11 ) );
// Join the tables using the Update Platform
dt << Update(
With( dt12 ),
Match Columns( :Pass = :Pass, :Cuvette = :Cuvette )
);
// Create the new Output column
dt << New Column( "Output", Set Each Value( :"850 nm"n / :Divisor ) );
// Remove Divisor column since it is no longer needed
dt << delete columns( Divisor );
// Close the subsetted data table since it is no longer needed
Close( dt12, nosave );
// Remove the Selected RowStates from the data table
dt << clear rowstates;
Di seguito è riportato un approccio più diretto, ma un metodo molto più inefficiente, che produce gli stessi risultati. Su una tabella dati di grandi dimensioni, questo metodo sarà piuttosto lento
Names Default To Here( 1 );
dt = Current Data Table();
dt << New Column( "Output",
Formula(
foundRow = [];
If( :Cuvette == 11,
curPass = :Pass;
foundRow = Current Data Table() <<
get rows where( :Cuvette == 12 & :Pass == curPass );
If( N Items( foundRow ) > 0,
:"850 nm"n / :"250 nm"n[foundRow[1]]
);
);
)
);
Re: Calcoli tra righe in base alle condizioniEcco un'opzione di matrice, ma l'utilizzo delle funzionalità JMP è generalmente più facile da capire
Names Default To Here(1);
dt = Current Data Table();
cuvette_start = 11;
cuvette_end = 12;
cuvettes = dt[0, "Cuvette"];
// Data is sorted -> we can just take values and make comparison
start_idx = Loc(cuvettes, cuvette_start);
end_idx = Loc(cuvettes, cuvette_end);
// differences
output = J(1, N Rows(dt), .);
output[start_idx] = dt[start_idx, "850 nm"] :\</img> dt[end_idx, "250 nm"];
dt << new column("R", Numeric, Continuous, Values(output));
Se puoi fare molto affidamento sull'ordine, puoi usare una formula come questa
If(:Cuvette == 11,
:"850 nm"n / :"250 nm"n[Col Min(If(:Cuvette == 12, Row(), .)) + Row() - 1];
);
Il tipo di formula finale dipenderà molto dal caso d'uso reale (i dati sono ordinati "correttamente", si sta cercando un confronto tra più valori e così via).