将一组列动态传递给表摘要函数我有一个生成表格的工作流程(附加示例),但是从 14 开始的列数和列名将根据最终用户正在查看的数据集而有所不同。
脚本的第一部分运行正常——生成列名列表。我遇到的难题是,如何将这个列表传回表汇总函数,这超出了我目前在 JSL 中所做的一切。坦白说,我确实尝试过用 MS Copilot 来解决这个问题(AI Agent 指向了 JMP 文档),但没有成功。
//num cols
dt = Data Table( "plate_data_wide_for_dynamic_summary Anonymized" );
nCols = N Col( dt );
//empty list of colnames, populate with col names from 14 to end of table
colnames = {};
For( i = 14, i <= nCols, i++,
Insert Into( colnames, Column( dt, i ) << Get Name )
);
//create summary expression with dynamic column placeholder
summaryExpr = Expr(
Data Table( "plate_data_wide_for_dynamic_summary Anonymized" ) << Summary(
Group(
:X__1, :X__3, :X__10
),
__DYNAMIC_COLUMNS__,
Freq( "None" ),
Weight( "None" ),
output table name( "Summarized by PC plate_well wide" )
)
);
//create list of summary statistics and columns to pass to summary function
dynamicCols = {};
For( i = 1, i <= N Items( colnames ), i++,
Insert Into( dynamicCols, Eval Expr( Median( As Column( dt, colnames[i] ) ) ) )
);
//pass dynamicCols list to summary expression and evaluate
Insert Into( summaryExpr[1][2], dynamicCols );
Eval( summaryExpr );
自动化和脚本回复:动态地将一组列传递给表摘要函数我相信这会给你你想要的东西
Names Default to Here( 1 );
dt = Data Table( "plate_data_wide_for_dynamic_summary Anonymized" );
nCols = N Col( dt );
//empty list of colnames, populate with col names from 14 to end of table
colnames = dt << get column names( string ); //num cols
staticNames = {"X__1", "X__3", "X__10"};
For Each( {sName}, staticNames, Try( Remove From( colnames, Contains( colnames, sName ), 1 ) ) );
//create summary expression with dynamic column placeholder
Eval(
Eval Expr(
Data Table( "plate_data_wide_for_dynamic_summary Anonymized" ) <<
Summary(
Group( Expr( staticNames ) ),
Median( Expr( colnames ) ),
Freq( "None" ),
Weight( "None" ),
output table name( "Summarized by PC plate_well wide" )
)
)
);

回复:动态地将一组列传递给表摘要函数太棒了,Jim,谢谢你!我稍微修改了一下,将列名 14 传递给 end,而不是传递给那些未用于分组的列。最终版本如下:
Names Default to Here( 1 );
dt = Data Table( "plate_data_wide_for_dynamic_summary Anonymized" );
nCols = N Col( dt );
//empty list of colnames, populate with col names from 14 to end of table
colnames = {};
For( i = 14, i <= nCols, i++,
Insert Into( colnames, Column( dt, i ) << Get Name )
);
GroupColNames = {"X__1", "X__3", "X__10"};
//create summary expression with dynamic column insertion
Eval(
Eval Expr(
Data Table( "plate_data_wide_for_dynamic_summary Anonymized" ) <<
Summary(
Group( Expr( GroupColNames ) ),
Median( Expr( colnames ) ),
Freq( "None" ),
Weight( "None" ),
output table name( "Summarized by PC plate_well wide" )
)
)
);