如何删除重复的行?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 ();