dt = Open( "$sample_data/big class.jmp" );
nr = N Rows( dt ); // needed below to find the end of the ascending sort list
rowsSortedByWeight = Rank( dt:weight << getvalues ); // Rank gives the indexes, ascending
heavyRows = rowsSortedByWeight[nr - 3 :: nr]; // four biggest at end
For Each( {r}, heavyRows, // get each row number into r from the heavyRows matrix
// look in the log for the report...
Write( Eval Insert( "\!nname=^dt:name[r]^ weight=^dt:weight[r]^" ) )
);
nome=KIRK peso=134
nome=LESLIE peso=142
nome=JACLYN peso=145
nome=LAWRENCE peso=172
modifica: funzionerà meglio con i valori mancanti:
dt = Open( "$sample_data/big class.jmp" );
rowsSortedByWeight = Rank( dt:weight << getvalues ); // Rank gives the indexes, ascending
nr = N Rows( rowsSortedByWeight ); // should handle missing values
heavyRows = rowsSortedByWeight[nr - 3 :: nr]; // four biggest at end
For Each( {r}, heavyRows, // get each row number into r from the heavyRows matrix
// look in the log for the report...
Write( Eval Insert( "\!nname=^dt:name[r]^ weight=^dt:weight[r]^" ) )
);
Rank() restituirà un breve elenco, senza indici per i valori mancanti, quindi utilizza il numero di righe nell'elenco classificato anziché il numero di righe nella tabella dati.
ulteriori modifiche: e se intendi selezionare le righe nella tabella,
dt << selectrows( heavyRows )
Grazie mille a Craige_Hales per la rapida risposta.
Funziona bene