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 )