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
名前=レスリー 体重=142
名前=ジャクリン 体重=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 )
Craige_Hales さんの迅速な対応に感謝します。
うまくいきます