Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Summary of Unknown Number of Columns

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Mar 9, 2012 12:19 PM
(3425 views)

Hi,

I would like to create a summary of all columns in a generic data table, where the number of columns are unknown.

Below is an example for a known data table. Any suggestions for an unknown number of columns?

Thanks,

Rob

dt = Open( "$SAMPLE_DATA/Big Class.JMP" );

dtsum1 = dt << Summary( N( :name ), N( :age ), N( :sex ), N( :height ), N( :weight ) );

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Summary accepts a list of columns as an argument. So this oneliner works too!

dt = Open**(** "$SAMPLE_DATA/Big Class.JMP" **)**;

dt<<Summary**(**N**(**dt<<get column names**))**;

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Summary of Unknown Number of Columns

There's probably a slicker way, but in situations like this I create dynamic code and then execute it:

dt = Open**(** "$SAMPLE_DATA/Big Class.JMP" **)**;

dt_cols = dt << get column names**(**string**)**;

for **(**i = **1**, i <= nitems**(**dt_cols**)**, i++,

if **(**i == **1**,

n_expr = "dtsum1 = dt << Summary( N(:name(\!"" ||

dt_cols**[**i**]** || "\!"))";

,

n_expr = n_expr || ", N(:name(\!"" || dt_cols**[**i**]** || "\!"))";

**)**;

**)**;

n_expr = n_expr || ")";

eval**(**parse**(**n_expr**))**;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Summary of Unknown Number of Columns

I suggest building an expression and then inserting references to each column:

dt = Open( "$SAMPLE_DATA/Big Class.JMP" );

summaryexpr=Expr(Summary());

for(i=1,i<=ncol(dt),i++,

insertinto(summaryexpr,insert(expr(N()),column(i)))

);

eval(substitute(expr(dt<<command),expr(command),summaryexpr));

Unless you are switching between data tables, you could simplify the last line by simply executing 'summaryexpr' rather than adding it as a command to 'dt'.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Summary of Unknown Number of Columns

Both solutions work great. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Summary accepts a list of columns as an argument. So this oneliner works too!

dt = Open**(** "$SAMPLE_DATA/Big Class.JMP" **)**;

dt<<Summary**(**N**(**dt<<get column names**))**;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Summary of Unknown Number of Columns

Very elegant. Thanks!