Summary of Unknown Number of Columns<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />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 ) );
Re: Summary of Unknown Number of ColumnsVery elegant. Thanks!
Re: Summary of Unknown Number of ColumnsSummary 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));
Re: Summary of Unknown Number of ColumnsBoth solutions work great. Thanks!
Re: Summary of Unknown Number of ColumnsI 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<
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'.
Re: Summary of Unknown Number of ColumnsThere'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));