Subscribe Bookmark RSS Feed

How to make Summary(Group) read in an array of columns?


Community Trekker


Jun 23, 2011

Hi, how to make a for loop list the statistic columns in Summary(Group) instead of writing out every one (as in my case the FruitType list may actually change)... thx, dj

FruitType={"Apple", "Orange", "Banana"}; //list of fruit columns showing weights of each fruit
FruitTypeN=N Items(FruitType);

//Summarize the average of each fruit type
For(t=1,t= Mean(parse(eval(":" || FruitType))),
Output Table Name("Fruit Type Average"));

Message was edited by: djhanson
I think what you are asking for is how to convert code such as:

Data Table( "Untitled 10" ) << Summary( Group, Mean( :apple ), Mean( :orange ) )

Into something more flexible, allowing a variable number of columns.

It is probably more convenient to re-shape the data first by stacking the columns:

lstCols = Data Table("Fruit Data") << Get Column Names;
tempTab = Data Table("Fruit Data") << Stack(
columns( lstCols ),
Source Label Column( "Fruit" ),
Stacked Data Column( "Data" )
tempTab << Summary( Group( :Fruit ), Mean( :Data ) );