如何刪除重複行?The deletion of duplicate rows is starting to frustrate me! I'm on version 18.
In the following script I have Sorted the table on SN (asc), Date & Time (desc). I then create a New Column "DuplicateFlag" and then apply the Formula If( Lag(:SN, 1) == :SN, 1, 0 ). This adds 0 for no duplicate and 1 for duplicate. We then Select the rows = to 1 and Delete the Selected Rows.<BR /><BR />This appears to work great when the Date and Time are of different values for the associated SN. However, when the Date & Time are the same for the associated SN it does not delete the duplicate SN.<BR /><BR />What suggestions to ensure that all duplicate SN's are successfully deleted.
// Sort the SIDE_1_PRE_MTG table by SN (ascending), Date (descending), and Time (descending)
dt_sort = dt_erroneousdelete << Sort(
By( :SN, :Date, :Time ),
Order( Ascending, Descending, Descending ),
Replace Table
);
// Add a DuplicateFlag column to mark duplicate SN entries
dt_sort << New Column("DuplicateFlag",
Numeric,
"Continuous",
Formula(
If( Lag(:SN, 1) == :SN, 1, 0 )
)
);
// Select rows where DuplicateFlag is 1 and delete them
dt_sort << Select Where( :DuplicateFlag == 1 );
dt_sort << Delete Rows; // Deletes the selected rows
// Remove the DuplicateFlag column after deleting duplicates
dt_sort << Delete Columns("DuplicateFlag");自動化和腳本編寫回覆: 如何刪除重複的行?JMP 數字日期/時間列非常有趣。我以後需要注意這一點。
感謝您的建議。
約翰
回覆: 如何刪除重複的行?我發現了我的問題,它與另一個我不知道有重複項的表的連接有關。一旦我透過刪除重複項清理了該表,一切就正常了。
我確實使用您的程式碼刪除了我加入的表中的重複項,它運作得很好。
謝謝
回覆: 如何刪除重複的行?JMP 日期和時間列是數字日期/時間列嗎?如果是這樣,「日期」列的顯示值可能會顯示相同,但實際數值(自 01JAN1904 以來的秒數)可能不同。將“日期”列的顯示格式變更為“Fixed Dec, 20, 4”,然後查看是否有差異。
回覆: 如何刪除重複的行?如果我正確理解您要執行的操作,「選擇重複行」應該可以工作https://www.jmp.com/support/help/en/18.0/#page/jmp/select-rows.shtml# 。您能否提供一個資料集(模型很可能很好),在其中標記要刪除的行。
回覆: 如何刪除重複的行?我確實嘗試過您提供的簡單建議,但它也不起作用。
問題似乎是當我排序的 3 列...
SN 升序、日期降序和時間降序(這會將 SN 的最新記錄放在頂部或第一個行)都是相同的值。根據所附的螢幕截圖,您可以看到 SN、日期和時間對於每個關聯的 SN 都是相同的值(我對每個匹配集進行了顏色編碼)。
回覆: 如何刪除重複的行?我不確定我是否完全遵循您所尋找的內容。類似這樣的東西可以工作,但是針對您的資料表進行了修改嗎?
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Select duplicate rows( Match( :age, :height ) );
dt << Delete rows ();