將一組列動態傳遞給表格摘要函數我有一個生成表格的工作流程(附加範例),但是從 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" )
)
)
);