重複行を削除するにはどうすればよいですか?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");自動化とスクリプトRe: 重複行を削除するにはどうすればいいですか?JMP の数値日付/時刻列は非常に興味深いです。今後は注意する必要があります。
ご提案ありがとうございます。
ジョン
Re: 重複行を削除するにはどうすればいいですか?問題が分かりました。それは、重複しているのに気付かなかった別のテーブルからの結合に関連していました。重複を削除してそのテーブルをクリーンアップすると、すべて正常に動作しました。
あなたのコードを使用して、結合したテーブル内の重複を削除しましたが、完璧に機能しました。
ありがとう
Re: 重複行を削除するにはどうすればいいですか?日付列と時刻列は JMP の数値日付/時刻列ですか? その場合、日付列の表示値は同じでも、実際の数値 (1904 年 1 月 1 日からの秒数) は異なる場合があります。日付列の表示形式を「固定 12 月 20 日 4 日」に変更して、違いがあるかどうかを確認します。
Re: 重複行を削除するにはどうすればいいですか?あなたがしようとしていることを正しく理解していれば、重複行の選択は機能するはずですhttps://www.jmp.com/support/help/en/18.0/#page/jmp/select-rows.shtml# 。削除する行をマークするデータセット (モックアップで十分でしょう) を提供できますか。
Re: 重複行を削除するにはどうすればいいですか?あなたが提案してくれた単純な提案を試してみましたが、それもうまくいきませんでした。
問題は、並べ替える 3 つの列の場合に発生するようです。
昇順の SN、降順の日付、および降順の時刻 (これにより、SN による最新のレコードが先頭または最初のインラインに表示されます) はすべて同じ値です。添付のスクリーン ショットによると、SN、日付、および時刻は、関連付けられている SN ごとにすべて同じ値であることがわかります (一致する各セットを色分けしました)。
Re: 重複行を削除するにはどうすればいいですか?あなたが探している内容を正確に理解できているかわかりません。これのようなものをデータ テーブルに合わせて変更すれば機能するでしょうか?
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Select duplicate rows( Match( :age, :height ) );
dt << Delete rows ();