cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Alex19
Level II

Combine Data by Row

Hello, 

I am trying to do the following:

Given Product Column and Lot Column, I need to create "Lots in Product" Column so that it combines all the "lots' based on the same product.

Alex19_0-1733840030799.png

The final purpose is to get the Tabulate:

Alex19_1-1733840281096.png

The X1, X2, X3, X4 does not have to be present in the single cell, this will work as well (whichever is easier):

Alex19_2-1733840342515.png

Manually this process is insane when I have a table of thousands of datapoints.

Thank you so much!

JMP table is attached.

Alex.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jackie_
Level VI

Re: Combine Data by Row

Here is one way

 

Names Default To Here(1);

dt = Current Data Table();	

custom_sql = Eval Insert(
"\[SELECT Product, GROUP_CONCAT(DISTINCT CAST("Lot" as TEXT)) as "Lots in Product"
FROM t1
GROUP BY Product
]\");

dt_concat = Query(
	Table(dt, "t1"),
	custom_sql
);

New window("Tablebox",<<Type("Dialog"),
Data Table Box( dt_concat ));

View solution in original post

4 REPLIES 4
hogi
Level XII

Re: Combine Data by Row

Very common question.

There are a lot of tricks and workarounds.

 

In a future version of JMP it will be very easy:

🙏 Summary and Tabulate: add aggregation option for Character columns 
... if enough users follow the link and vote.

Jackie_
Level VI

Re: Combine Data by Row

Here is one way

 

Names Default To Here(1);

dt = Current Data Table();	

custom_sql = Eval Insert(
"\[SELECT Product, GROUP_CONCAT(DISTINCT CAST("Lot" as TEXT)) as "Lots in Product"
FROM t1
GROUP BY Product
]\");

dt_concat = Query(
	Table(dt, "t1"),
	custom_sql
);

New window("Tablebox",<<Type("Dialog"),
Data Table Box( dt_concat ));
hogi
Level XII

Re: Combine Data by Row

another one:

dt = Current Data Table();
dt << New Column( "rank", Formula( Col Rank( 1, :Product ) ), );

dtsplit = dt << Split(
	Split By( :rank ),
	Split( :Lot ),
	Group( :Product ),
	Remaining Columns( Drop All ), 

);

cols = dt split << get column names();
cols = cols[2 :: N Items( cols )];

dt split << New Column( "concat", Character, Set Each value( Concat Items( cols, "," ) ) );

dt << Update(
	With( dt split),
	Match Columns( :Product = :Product ),
	Add Columns from Update Table( :concat ),
	Replace Columns in Main Table( None )
);
Alex19
Level II

Re: Combine Data by Row

Works beautifully! Thank you!