按行過濾、堆疊列?我知道如何根據某些標準製作子集表:
dt << Row Selection( Select where( (:Stat == "mean"), Current Selection( Extend )) );
dt << Select Columns( [10, 20] );
dt2 << Subset( Output Table( "test"), Selected Rows( 1 ), Selected columns( 1 ) );
但現在我需要對多個條件重複上述操作並堆疊選擇,即新表將第 10 列作為固定列,然後我繼續添加第 20 列,僅包含與上述條件匹配的行。行數將始終相同。
「Stack」指令不適用於選擇,因此不確定還有哪些其他指令可以做到這一點?
資料混合與清理回复:按行過濾,堆疊列?這正是我想要的,再次感謝!
回复:按行過濾,堆疊列?重新考慮我猜測的是您想要的最終表輸出,我建議您看一下
表格=>拆分
下面的示例按 :Sex 列拆分,這將是您的 :Freq 列,拆分列是身高和體重,這將是您的 15 和 19 列。
輸出為每個 Split By 列值創建列對
Names Default To Here( 1 );
dt = open("$SAMPLE_DATA\big class.jmp");
// Split data table
// → Data Table( "Untitled 66" )
Data Table( "big class" ) << Split(
Split By( :Sex ),
Split( :height, :weight ),
Remaining Columns( Drop All ),
Sort by Column Property
);

回复:按行過濾,堆疊列?謝謝,這是正確的! 唯一剩下的就是如何將它放入 for 循環中。 這是我的審判:
For(i=1, i<=NItems(freq_list), i++,
dt << clear select;
dt << Row Selection( Select where( (:Freq == (freq_list[i])), Current Selection( Extend )) );
dt << Select Columns( [15,19] );
dt << Subset( ( Selected Columns ), Output Table Name( freq_list[i] ) );
);
但這會產生兩個相同的表,即使我在每個循環開始時清除了選擇。
回复:按行過濾,堆疊列?我懷疑問題是兩個表中的列具有相同的名稱。因此,JMP 將覆蓋這些值。這是一個簡單的例子,說明我將如何處理這個問題。現在,給定這種類型的更新,兩個數據表將排成一行,第 1 行與第 1 行。
這可能會導致無法跨列進行比較的問題,因為它們之間的關係不存在。
dt << Row Selection( Select where( (:Freq == "F0"), Current Selection( Extend )) );
dt << Select Columns( [15,19] );
dt2 = dt << Subset( ( Selected Columns ), Output Table Name( "F0" ) );
dt << clear select;
dt << Row Selection( Select where( (:Freq == "F1"), Current Selection( Extend )) );
dt << Select Columns( [15,19] );
dt3 = dt << Subset( ( Selected Columns ), Output Table Name( "F1" ) );
// Rename the columns
column(dt3,1) <<SET name=""></SET>
回复:按行過濾,堆疊列?我為很多帖子道歉。 我仍然卡住了。 現在我所擁有的就是這個腳本,它會生成兩個表,每個表都有一個我感興趣的列。 我可以手動將表 1 中的一列複製並粘貼到表 2,但不能自動執行。
dt << Row Selection( Select where( (:Freq == "F0"), Current Selection( Extend )) );
dt << Select Columns( [15,19] );
dt << Subset( ( Selected Columns ), Output Table Name( "F0" ) );
dt << clear select;
dt << Row Selection( Select where( (:Freq == "F1"), Current Selection( Extend )) );
dt << Select Columns( [15,19] );
dt << Subset( ( Selected Columns ), Output Table Name( "F1" ) );
回复:按行過濾,堆疊列?不,上面的代碼仍然串聯。 我會嘗試“更新”命令。
回复:按行過濾,堆疊列?這是一個似乎可以手動工作的代碼。 現在我將嘗試循環執行:
dt << Row Selection( Select where( (:Stat == "selection1"), Current Selection( Extend )) );
dt << Select Columns( [15, 19] );
dt << Row Selection( Select where( (:Stat == "selection2"), Current Selection( Extend )) );
dt << Select Columns( [15, 19] );
dt << Subset( ( Selected Columns ), Output Table Name( "Subset_1_2" ) );
回复:按行過濾,堆疊列?如果不連接,而是添加新列,則只需使用更新平台即可。
回复:按行過濾,堆疊列?謝謝,這幾乎就是我想要的,除了我需要它們堆疊(按列)而不是連接(按行)。 也就是說,如果選擇列是 L 長,我希望我的新表具有相同的行數,但有兩列(不是一列長度的兩倍)。回复:按行過濾,堆疊列?插入()不做你認為它做的事情。
在您的代碼中,它會重複將數據表引用 dt 插入到 dtstacked 列表中。 它與選定的行或列沒有任何關係。
您需要使用 Subset() 創建所選行和列的新數據表,並將該引用插入到 dtstacked 中,然後連接它們。
雖然,這似乎沒有必要。 由於您只是在最後通過循環每次都擴展選擇,因此您可以對選定的行和列執行一個子集,並獲得與串聯數據表相同的結果。
回复:按行過濾,堆疊列?謝謝,但它沒有用:
dt = current data table();
my_list = {"F0","F1"};
dtBase = New Table("Base");
dtStacked = {};
For( i = 1, i <= N Items( my_list ), i++,
dt << Row Selection( Select where( (:Freq==my_list[i]), Current Selection( "Extend" )) );
dt << Select Columns( [19] );
Insert Into( dtStacked, dt );
dtBase << Concatenate( dtStacked );
Close( dtStacked, nosave );
);dtBase 為空。
回复:按行過濾,堆疊列?啊.....你是正確的關於刪除選定的行。但是要刪除未選中的,只需使用
dtStack << Invert Row Selection;
然後刪除行。
要附加多個獨立的 Stacked 數據表,只需:
- 在開始重複 Stack 實例之前,創建一個空的 Base 數據表,最終將所有堆疊表連接到它
dtBase = New Table("Base");
- 然後對於您創建的每個堆疊表,
- 從堆疊數據表中刪除不需要的行
- 將 Stacked 表連接到 Base 表
dtBase << Concatenate( dtStacked );
- 刪除堆疊表
Close( dtStacked, nosave );
回复:按行過濾,堆疊列?這是我認為可以完成的方式(但它不起作用):
my_list = {"F0","F1"};
stackcols = {};
For( i = 1, i <= N Items( my_list ), i++,
dt << Row Selection( Select where( (:Freq==my_list[i]), Current Selection( "Extend" )) );
dt << Select Columns( [19] );
Insert Into( stackcols, dt )
);
dt2 << Subset( Output Table( "aa"), Selected Rows( 1 ), Selected columns( 1 ) );基本上,我根據“Freq”列過濾活動表,首先按值“F0”,然後按“F1”。 它位於第 19 列。 我將該選擇添加到名為“stackcols”的選擇列表中。 所以在循環之後我期望這是一個兩列寬的列表。 然後我想用它製作一張桌子(稱為“aa”)。 但它不起作用。
回复:按行過濾,堆疊列?(誤點擊接受為解決方案)
謝謝,但我不想刪除選定的行。 我可以解決這個問題,但是在使用 Stack 時如何附加選擇?回复:按行過濾,堆疊列?以下是使用 Stack 平台時刪除所選行的簡單方法示例
names default to here(1);
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Row Selection( Select where( (:Sex=="F"), Current Selection( "Extend" )) );
// Stack data table
dtStack = dt << Stack(
columns( :height, :weight ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" )
);
dtStack << delete rows;