根據條件選擇並刪除重複行嗨,大家好,
我在論壇上搜尋過,但沒有接近我想要實現的目標,或者也許我錯過了。

無論如何,我需要有關上表的協助。 可以看出,我有一個按顏色突出顯示的重複項。 大多數零件的序號是相同的,因為零件在不同的部分進行檢查(如圖1A、1B、2A、2B、3A、3B、4A、4B所示)。 通常,如果零件未通過檢查,則會重新檢查,這會顯示在重新測試欄中(0表示不重新測試,1表示第一次,等等..) 現在我只能透過同一序號內的重測次數或日期來區分零件,因此我想保留最新的重測結果並刪除先前的重複結果。 意思是說,按照上面突出顯示的框,對於藍色或紅色,我想保留重新測試 1 並刪除重新測試 0。 這對我來說有點頭疼,所以我需要社區對腳本的建議,以選擇序號和部分中的條件來找出最新的重新測試,然後保留最新的重新測試並刪除先前的重複項。 希望大家對此有意見。 謝謝
回覆:根據條件選擇並刪除重複行如果您想刪除與除一列(或幾列)之外的所有列相符的重複行,這是我的工作解決方案。
優點是不需要指定每個列名。
// delete duplicate rows, where only column ID is different
column_list = dtProcess << Get Column Names( string );
Remove From( column_list, As List( Loc( column_list, "ID" ) ) ); // remove "ID"
dtProcess << Select Duplicate Rows( Match(As List(column_list)));
doublerows = dtProcess << get selected rows;
num_selected = n rows(doublerows);
if(num_selected >0,
dtProcess << delete rows;
print("Removed " || char(num_selected) || " rows from process table.")
,
print("No duplicate rows in process table, excluding column ID.")
);:
回覆:根據條件選擇並刪除重複行很有幫助! 謝謝!
我正在建立一個類似的東西,不知何故我的組合在列選擇上出錯了。
謝謝你!
回覆:根據條件選擇並刪除重複行我做了一些修改以適合我的桌子。 謝謝!
回覆:根據條件選擇並刪除重複行如果您有早期版本的 JMP, <<選擇重複行可能不可用。 然後嘗試下面的方法。 程式碼應選擇並刪除具有最早日期的重複行(基於匹配的序號和部分)。 排序並不重要。
dt = Current Data Table();
dt << select where(Col Max(:Date, :SerialNo, :Section) > :Date());
dt << delete rows();
回覆:根據條件選擇並刪除重複行有一個函數叫做
選擇重複行()
可以用於此目的,但是它基於查找唯一行之後的行。因此,在使用函數之前需要對錶進行反向排序。下面是執行此操作的範例腳本。由於我沒有用於運行此腳本的範例資料表,因此該腳本尚未經過測試,但它非常接近您所需要的。
有關該函數的文件可以在腳本索引中找到
Names Default To Here( 1 );
dt = Current Data Table();
// Add a new column to preserve the current order
dt << New Column( "rowNum", formula( Row() ) );
// Remove the formula to convert values to static values
:rowNum << delete property( "formula" );
// Sort the data table in referse order, since one wants to
// keep the most recent value
dt << sort( by( rowNum ), order( descending ), Replace Table( 1 ) );
// Find the duplicate rows
dt << Select Duplicate Rows( Match( :SerialNo, :Date, :Retest ) );
// Delete Duplicates
dt << delete rows;
// Reorder the table
dt << sort( by( rowNum ), order( ascending ), Replace Table( 1 ) );
// Delete rowNum column
dt << delete columns( "rowNum" );