cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Konstantinos
Level II

Script for removing duplicate rows

Hi,

 

I have a script where I update a table by another one.

For the final table, I would like to remove duplicate rows based on defined columns.

Thereby, the row with the lower row number should be deleted. 

 

In the following you can see an example for better illustration:

 

RowDateABCD
122.10.2021110415
223.10.2021215827
326.10.2021325 
425.10.2021471312
526.10.20213256

 

For this table, the duplicate rows are defined by the columns :Date, :A and :B.

Row 3 should be deleted and row 5 kept.

Could you provide me with a JSL code for that example?

 

Many thanks in advance.

 

Best Regards

 

Konstantinos

 

 

4 REPLIES 4
jthi
Super User

Re: Script for removing duplicate rows

JMPs interactive Select Dublicate Rows with Delete Rows should be able to do this.

Select columns of interest:

jthi_0-1635417088099.png

Go to Rows / Row Selection / Select Dublicate Rows:

jthi_1-1635417113039.png

Right click on row number and Delete Rows:

jthi_2-1635417132091.png

If you have JMP16 repeat same steps while you have Enhanced log enabled, it will return you the script:

// Delete selected rows
Data Table("Untitled") << Select Duplicate Rows(Match(:Date, :A, :B)) << Delete Rows;

(update the script to use references).

 

 

 

-Jarmo
Konstantinos
Level II

Re: Script for removing duplicate rows

Thanks for your prompt reply. Unfortunately, that does not fulfill my requirement. I want that row 3 is deleted and not row 5.

jthi
Super User

Re: Script for removing duplicate rows

One option would be to sort the data first by Row number -> delete duplicates and then sort again.

-Jarmo
jthi
Super User

Re: Script for removing duplicate rows

You could also create formula to count unique values. Something like this might work:

Col Number(:Date, :A, :B) - Col Cumulative Sum(1, :Date, :A, :B)

Select all 0 values and invert selection. Then delete rows.

-Jarmo