使用 JSL 選擇動態數量的列,選擇符合條件的列https://www.jmp.com/support/help/14-2/use-set-selected-to-select-columns.shtml
重寫這樣的東西的最佳方法是什麼?
其目的是 DT 是 TRANSPOSE 和 CATEGORY_TABLE 的連結。
- CATEGORY_TABLE 是一個單列表,其中包含類別列
- TRANSPOSE 是資料轉置的結果
訣竅在於 TRANSPOSE 並不總是具有相同的列數。令人困惑的是,轉置函數的輸出將附加列命名為「行 1」、「行 2」等。
- TRANSPOSE 的前兩列始終相同。
- 列行 1 將始終作為第三列存在。
- 根據資料集的不同,可能存在第 2 行及之後的列。
我是否可以以這樣的方式編寫 Select() 函數,使得 Join() 至少選擇第 1 列,然後如果最後一列還有更多列?
// This section is only build to handle two columns named Row 1 and Row 2
DT = Data Table( TRANSPOSE ) << Join(
With( Data Table( CATEGORY_TABLE ) ),
Select( :Forecast Material ),
SelectWith( :Category ),
Select( :Row 1, :Row 2 ), // sometimes there is only one row, sometimes there are more than one rows ******How to handle this?********
By Matching Columns( :Label = :Category ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 )
);
回覆:使用 JSL 選擇動態行數,選擇符合條件的行謝謝BSwid。讓我知道它是如何工作的。
回覆:使用 JSL 選擇動態行數,選擇符合條件的行謝謝唐。我正在嘗試更新別人的程式碼。我認為這就是我們想要的。在接受解決方案之前需要花一些時間進行驗證。不想讓您認為我沒有看到並感謝您的回覆。昨天正在研究這個建議。謝謝!回覆:使用 JSL 選擇動態行數,選擇符合條件的行刪除其中包含“Select”的參數:
DT = Data Table( TRANSPOSE ) << Join(
With( Data Table( CATEGORY_TABLE ) ),
By Matching Columns( :Label = :Category ),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 )
);
結果將包含兩個表中的所有欄位。
回覆:使用 JSL 選擇動態行數,選擇符合條件的行我嘗試了類似的操作,但收到錯誤Column not found {1} in access orvaluation of 'Bad Argument'
我想這是Join()中Select()內的爭論。
我想也許我可以將列向量分配給變數並使用該變數作為 Select() 中的參數。
// Get a list of the column names
colList = TRANSPOSE << Get Column Names();
// Starting with column 3, select
For(i=3,i<= N Cols( TRANSPOSE ), i++, COLUMN( TRANSPOSE , colList[i]) << Set Selected(1) ) ;
// Assign those selected columns to a variable
Select_cols = TRANSPOSE << Get Selected Columns();
//then feed that variable into the Select() withing Join()
<SPAN class="token comment">// 加入</SPAN>
DT <SPAN class="token operator">=</SPAN> <SPAN class="token function">數據表</SPAN><SPAN class="token punctuation">(</SPAN> TRANSPOSE <SPAN class="token punctuation">)</SPAN> <SPAN class="token operator"><</SPAN><SPAN class="token operator"><</SPAN><SPAN class="token messages">加入</SPAN><SPAN class="token punctuation">(</SPAN>
With<SPAN class="token punctuation">(</SPAN> <SPAN class="token function">數據表</SPAN><SPAN class="token punctuation">(</SPAN> CATEGORY_TABLE <SPAN class="token punctuation">)</SPAN> <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">,</SPAN>
Select<SPAN class="token punctuation">(</SPAN> <SPAN class="token punctuation">:</SPAN>Forecast Material <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">,</SPAN>
SelectWith<SPAN class="token punctuation">(</SPAN> <SPAN class="token punctuation">:</SPAN>Category <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">,</SPAN>
Select<SPAN class="token punctuation">(</SPAN> Select_cols <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">,</SPAN> /// was Select<SPAN class="token punctuation">(</SPAN> <SPAN class="token punctuation">:</SPAN>Row <SPAN class="token number">1</SPAN><SPAN class="token punctuation">,</SPAN> <SPAN class="token punctuation">:</SPAN>Row <SPAN class="token number">2</SPAN> <SPAN class="token punctuation">)</SPAN>
By Matching Columns<SPAN class="token punctuation">(</SPAN> <SPAN class="token punctuation">:</SPAN>Label <SPAN class="token operator">=</SPAN> <SPAN class="token punctuation">:</SPAN>Category <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">,</SPAN>
Drop multiples<SPAN class="token punctuation">(</SPAN> <SPAN class="token number">0</SPAN><SPAN class="token punctuation">,</SPAN> <SPAN class="token number">0</SPAN> <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">,</SPAN>
Include Nonmatches<SPAN class="token punctuation">(</SPAN> <SPAN class="token number">0</SPAN><SPAN class="token punctuation">,</SPAN> <SPAN class="token number">0</SPAN> <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">,</SPAN>
Preserve main table order<SPAN class="token punctuation">(</SPAN> <SPAN class="token number">1</SPAN> <SPAN class="token punctuation">)</SPAN>
<SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>