cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
Choose Language Hide Translation Bar
UserID16644
Level V

How to get value of duplicate columns?

Hi all,

How can I get the value of a Column A and place it with the duplicate value in Column B?

 

For example, this is my data:

Column A Column B
A Apple
  Apple
B Banana
  Mango
C Mango

 

 

This is the expected output:

Column A Column B
A Apple
A Apple
B Banana
C Mango
C Mango
2 REPLIES 2
txnelson
Super User

Re: How to get value of duplicate columns?

If you sort your data where the non blank value of Column A is always first, and then select all Column A rows

You can right click on the value for row 1 for Column A and select

txnelson_1-1744115318687.png

 

Here is a alternative JSL solution

txnelson_0-1744114936234.png

 

Names Default To Here( 1 );

// Create the sample data table
dt = New Table( "Example",
	Add Rows( 5 ),
	New Column( "Column A",
		Character,
		"Nominal",
		Set Values( {"A", "", "B", "", "C"} )
	),
	New Column( "Column B",
		Character,
		"Nominal",
		Set Values( {"Apple", "Apple", "Banana", "Mango", "Mango"} )
	)
);

// Sort the table to allow non black Column A rows to be first
dt << Data Table( "Example" ) << Sort(
	By( :Column B, :Column A ),
	Order( Ascending, Descending ),
	Replace Table( 1 )
);

// Modify the Column A 
Hold = "";
For Each Row(
	If( :Column A != "",
		Hold = :Column A,
		Show( Lag( :column b ), :column b );
		If( Lag( :Column B ) == :Column B,
			:Column A = Hold
		);
	)
);

 

Jim
pmroz
Super User

Re: How to get value of duplicate columns?

Here's another approach that uses the tabulate platform.  Sorting is not requred.

dt = New Table( "Test", Add Rows( 5 ),
	New Column( "Column A", Character, "Nominal",
		Set Values( {"A", "", "B", "", "C"} ) ),
	New Column( "Column B", Character( 16 ), "Nominal",
		Set Values( {"Apple", "Apple", "Banana", "Mango", "Mango"} ) )
);
dtab = dt << Tabulate(
	Show Control Panel( 0 ), invisible,
	Add Table( Row Table( Grouping Columns( :Column A, :Column B ) ) )
);
dt2 = dtab << Make Into Data Table (invisible);
dtab << close window;
for (i = 1, i <= nrows(dt2), i++,
	one_key = dt2:Column B[i];
	one_value = dt2:Column A[i];

	rowset = dt << get rows where(dt:Column B == one_key & dt:Column A == "");
	dt:Column A[rowset] = one_value;
);
close(dt2, nosave);

Recommended Articles