如何使用列表選擇具有特定值的行嗨,我正在嘗試使用填充一列的名稱列表來選擇另一列(在另一個表中)的匹配行,以便對該表進行子集化並生成幾個不同的子集。
從第一列獲取名稱/值沒問題,但是我找不到循環的正確語法。
dt4 = Current Data Table();
uniqueVals = {"2021_file1_T1", "2021_file1_T2"};
tableList= {};
For(i=1, i< N Items(uniqueVals), i++,
dt4 << select where( As Column("Type") == [i] ) );
dt4 << Select Columns (all);
newdt[i] = dt4 << Subset( Selected columns );
Insert Into(tableList, Data Table(newdt[i]));
dt4 << Clear Column Selection();
dt4 << Clear Select();
);// end of For我認為我的基本邏輯還可以,因為這段代碼運行得很好
dt4 << select where( As Column("Type") =="2021_file1_T2");
dt4 << Select Columns(all);
dt4 << Subset (Selected columns);但是我不知道如何將[i]傳遞給“選擇位置”。隨附的是簡化的測試表。
我將不勝感激任何提示/解決方案/建議。
腳本編寫回复:如何使用列表選擇具有特定值的行您可以輕鬆完成所需的工作。以下是我對您的代碼的修改。請注意,您要引用的newdt列表中的tableList列表是多餘的。
dt4 = Current Data Table();
uniqueVals = {"2021_file1_T1", "2021_file1_T2"};
//tableList = {};
newdt = {};
For( i = 1, i <= N Items( uniqueVals ), i++,
dt4 << select where( As Column( "Type" ) == uniqueVals[i] );
dt4 << Select Columns( all );
newdt[i] = dt4 << Subset( Selected columns );
//Insert Into( tableList, Data Table( newdt[i] ) );
dt4 << Clear Column Selection();
dt4 << Clear Select();
);