수천 개의 열이 있는 데이터 테이블이 있습니다. 다른 변수로 해당 열에서 상위 "X"개의 값을 찾고 있습니다. 예를 들어 다른 열에 "Large Cap Stocks" 값이 있을 때 가장 높은 값이 10개 있는 열을 알고 싶습니다.
데이터에 대한 개념 없이 먼저 데이터를 쌓은 다음 상위 10개 값을 선택하는 것이 가장 쉬울 수 있습니다.
다음은 단 하나의 열로 수행하는 방법입니다. 이것을 각 열에 대한 루프에 넣을 수 있습니다. 이 게시물 더 많은 배경이 있습니다.
/*JMP STATISTICAL DISCOVERY LLC (“JMP”) PERMITS THE USE OF THIS COMPUTER SOFTWARE CODE (“CODE”) ON AN AS-IS BASIS AND AUTHORIZES YOU TO USE THE CODE SUBJECT TO THE TERMS LISTED HEREIN. BY USING THE CODE, YOU AGREE TO THESE TERMS. YOUR USE OF THE CODE IS AT YOUR OWN RISK. JMP MAKES NO REPRESENTATION OR WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRIGEMENT, AND TITLE, WITH RESPECT TO THE CODE.
You may use the Code solely as part of a software product you currently have licensed from JMP, JMP’s parent company SAS Institute Inc. (“SAS”), or one of JMP’s or SAS’s subsidiaries or authorized agents (the “Software”), and not for any other purpose. The Code is designed to add functionality to the Software but has not necessarily been tested. Accordingly, JMP makes no representation or warranty that the Code will operate error-free. JMP is under no obligation to maintain, support, or continue to distribute the Code.
Neither JMP nor its licensors shall be liable to you or any third-party for any general, special, direct, indirect, consequential, incidental, or other damages whatsoever arising out of or related to your use or inability to use the Code, even if JMP has been advised of the possibility of such damages. Except as otherwise provided above, the Code is governed by the same agreement that governs the Software. If you do not have an existing agreement with JMP or SAS governing the Software, you may not use the Code.
JMP and all other JMP Statistical Discovery LLC product or service names are registered trademarks or trademarks of JMP Statistical Discovery LLC in the USA and other countries. ® indicates USA registration. Other brand and product names are registered trademarks or trademarks of their respective companies.
*/
//init
n = N Rows();
lstCategories = Associative Array( :Stock Type << Get Values ) << Get Keys;
lstRows = {};
dt = Current Data Table();
dt << Clear Column Selection;
dt << Clear Select;
//loop through each category for first column; save top 10 for each category into lstRows
For Each( {i}, lstCategories,
dt << Select Where( :Stock Type != i );
dt << Hide and Exclude;
dt << Clear Select;
dt << select rows( Loc( Ranking( :"Value 1"n[1 :: n] ) >= n - 10 ) );
t = As List( dt << Get Selected Rows );
Show( i );
Show( t );
dt << Clear Row States;
Insert Into( lstRows, t );
);
//do something with the rows
dt << Select Rows( lstRows );
와우, Loc(순위...)가 훌륭하네요! 정말 유용하네요!
방금 질문을 읽고 궁금했어요.
@dkraeuter_sunne 님 이 썼습니다:
가장 높은 값 10개가 있는 열
- 각 행마다?
그러면 그럴 수도 있겠다
dt = Current Data Table();
nc = N Cols();
Row() = 4;
For Each Row(
If( :Stock Type == "Large Cap Stock",
mx = Max( dt[Row(), 2 :: nc] );
colnumbers = Loc( Ranking( mx - dt[Row(), 2 :: nc] ) <= 10 );
colnames = Transform Each( {col}, As List( colnumbers ), Column( col + 1 ) << get name );
Print( Row(), colnames );
)
);
"열 27"과 그 이하에는 누락된 값이 많습니다. 분석에 포함해야 합니까?