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]^" ) )
);
이름=KIRK 가중치=134
이름=LESLIE 체중=142
이름=JACLYN 체중=145
이름=LAWRENCE 가중치=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에게 감사드립니다.
잘 작동한다