Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Level V

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

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

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

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 ) );
Article Labels

    There are no labels assigned to this post.