cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
0 Kudos

Summerize/Summary aggregation function for character data. Concat Charcter Vector into a Scalar (by)

Generalize the code to work with Summerize/Summary.

 

dt = current data table();

Summarize( g = By(:Column 0, :Column 1 ) );

For( i = 1, i <= N Items( g[1] ), i++,

   r = dt << Get Rows Where( dt:Column 0 == g[1][i] & dt:Column 1 == g[2][i]);

   dt:Column 3[r] = Concat Items( dt:Column 2[r], "_" );

);

nt = dt << Summary( Group( :Column 0, :Column 1, :Column 3 ) );

3 Comments
Ryan_Gilmore
Community Manager
Status changed to: Archived
We are archiving this request. If this is still important please comment with additional details and we will reopen. Thank you!
hogi
Level XII

very useful

Up to now, I used Split to sort the entries, combine them and merge them back to the main table:

Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

//-------- dt << new column ("rank", Formula( Col Rank( :name, :age ) )); // put names next to each other, grouped by age DTsplit=dt<< Split( Split By( :rank), Split( :name ), Group( :age ) ); // Combine columns to a linge column DTsplit << Combine Columns( columns( :"1"n, :"2"n, :"3"n, :"4"n, :"5"n, :"6"n, :"7"n, :"8"n, :"9"n, :"10"n, :"11"n, :"12"n ), Column Name( "allNames" ), Delimiter( "," ) );

//----- // Update data tables dt<< Update( With( DTsplit ), Match Columns( :age = :age ), Add Columns from Update Table( :allNames ), Replace Columns in Main Table( None ) );

to get:

hogi_0-1689538145514.png

 

If Summarize had an option to concatenate strings, the whole part between the //---- could be replaced by a simple Summarize.

hogi
Level XII