cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Stijnw91
Level I

Selecting duplicates from different source columns

Hello,

 

I'm trying to select (and delete) duplicates after combining two data tables with a source column, I have 2 criteria for a selection:

-The duplicate values should match in 2 columns (Match :col1, :col2), works fine.

-The duplicate values should not have the same value in the generated source column.

 

I'm not sure how I can code the 2nd criterium, is there some simple != line or 'does not' match ':Source Table'?

 

dt1 << concatenate (dt1, dt2, append to first table(1), Create Source Column ) ;		
dt1 << Select Duplicate Rows (Match (:col1, :col2)) ;

dt1 << Delete Rows();
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Selecting duplicates from different source columns

I think you need to take a different approach.  Your submitted JSL has a couple of issues, and a misinterpretation of the Select Duplicate Rows function.

Your Concatenation statement creates a new data table where your data table dt1 is replicated twice in the output table.

The Select Duplicate Rows function only finds duplicates within the same column.

I suggest you look into using the Join platform, which has the capability of determining which rows between the 2 data tables have duplicate values.

Here is an example of comparing between 2 data tables and finding that the person named Robert is in both tables.

txnelson_0-1688490605407.png

Names Default To Here( 1 );
dt1 = New Table( "one",
	Add Rows( 20 ),
	New Column( "name",
		Character,
		"Nominal",
		Set Values(
			{"KATIE", "LOUISE", "JANE", "JACLYN", "LILLIE", "TIM", "JAMES", "ROBERT", "BARBARA", "ALICE",
			"SUSAN", "JOHN", "JOE", "MICHAEL", "DAVID", "JUDY", "ELIZABETH", "LESLIE", "CAROL", "PATTY"}
		)
	)
);

dt2 = New Table( "Two",
	Add Rows( 20 ),
	New Column( "name",
		Character,
		"Nominal",
		Set Values(
			{"FREDERICK", "ALFRED", "HENRY", "LEWIS", "EDWARD", "CHRIS", "JEFFREY", "MARY", "AMY", "ROBERT",
			"WILLIAM", "CLAY", "MARK", "DANNY", "MARTHA", "MARION", "PHILLIP", "LINDA", "KIRK", "LAWRENCE"}
		)
	)
);

dt3 = dt1 << Join(
	With( dt2 ),
	Merge Same Name Columns,
	By Matching Columns( :name = :name ),
	Drop multiples( 1, 0 ),
	Include Nonmatches( 1, 1 ),
	Preserve main table order( 1 ),
	Output Table( "together" )
);

dt3 << select where( :Match Flag == 3 );

//dt3 << Delete Rows();
//dt3 << delete columns(match flag);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Selecting duplicates from different source columns

I think you need to take a different approach.  Your submitted JSL has a couple of issues, and a misinterpretation of the Select Duplicate Rows function.

Your Concatenation statement creates a new data table where your data table dt1 is replicated twice in the output table.

The Select Duplicate Rows function only finds duplicates within the same column.

I suggest you look into using the Join platform, which has the capability of determining which rows between the 2 data tables have duplicate values.

Here is an example of comparing between 2 data tables and finding that the person named Robert is in both tables.

txnelson_0-1688490605407.png

Names Default To Here( 1 );
dt1 = New Table( "one",
	Add Rows( 20 ),
	New Column( "name",
		Character,
		"Nominal",
		Set Values(
			{"KATIE", "LOUISE", "JANE", "JACLYN", "LILLIE", "TIM", "JAMES", "ROBERT", "BARBARA", "ALICE",
			"SUSAN", "JOHN", "JOE", "MICHAEL", "DAVID", "JUDY", "ELIZABETH", "LESLIE", "CAROL", "PATTY"}
		)
	)
);

dt2 = New Table( "Two",
	Add Rows( 20 ),
	New Column( "name",
		Character,
		"Nominal",
		Set Values(
			{"FREDERICK", "ALFRED", "HENRY", "LEWIS", "EDWARD", "CHRIS", "JEFFREY", "MARY", "AMY", "ROBERT",
			"WILLIAM", "CLAY", "MARK", "DANNY", "MARTHA", "MARION", "PHILLIP", "LINDA", "KIRK", "LAWRENCE"}
		)
	)
);

dt3 = dt1 << Join(
	With( dt2 ),
	Merge Same Name Columns,
	By Matching Columns( :name = :name ),
	Drop multiples( 1, 0 ),
	Include Nonmatches( 1, 1 ),
	Preserve main table order( 1 ),
	Output Table( "together" )
);

dt3 << select where( :Match Flag == 3 );

//dt3 << Delete Rows();
//dt3 << delete columns(match flag);
Jim
Stijnw91
Level I

Re: Selecting duplicates from different source columns

Thanks Jim, this works well!

Happy to learn more about the Join function.

 

Regards,

Stijn

Recommended Articles