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]^" ) )
);
姓名=柯克 體重=134
姓名=LESLIE 體重=142
姓名=JACLYN 體重=145
姓名=勞倫斯 體重=172
編輯:這對於缺失值會更好:
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() 將傳回一個簡短的列表,沒有缺失值的索引,因此使用排名列表中的行數而不是資料表中的行數。
更多編輯:如果您想選擇表中的行,
dt << selectrows( heavyRows )