There are several ways to approach this, but the one I find the easiest is to use
Tables==>Summary
to do the summarization, and then to merge the summary data back into the original table. Here is a simple script that uses your example data to do that
Names Default To Here( 1 );
// Create an example data table
dt = New Table( "Example",
Add Rows( 10 ),
New Column( "Matching Column",
Character,
"Nominal",
Set Values( {"a", "a", "b", "b", "b", "c", "c", "c", "d", "d"} )
),
New Column( "Numbers",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2, 4, 2, 4, 6, 3, 6, 9, 2, 2] )
)
);
// Pause so one can see the original table
wait(5);
// Summarize the data
dtSum = dt << Summary(
invisible,
Group( :Matching Column ),
Mean( :Numbers ),
Freq( "None" ),
Weight( "None" ),
statistics column name format( "column" ),
Link to original data table( 0 ),
output table name( "Means" )
);
// Adjust items in summary data to allow for proper merging
dtSum << delete columns( "N Rows" );
dtSum:Numbers << Set Name( "Average of grouped numbers" );
// Add the summary data to the original data table
dt << Update( With( dtSum ), Match Columns( :Matching Column = :Matching Column ) );
// Clean up the environment
Close( dtSum, nosave );
Jim