将脚本应用于多个数据表我有一个脚本,在 JMP 中打开一个 txt 文件作为数据表,然后将第 7 行中列出的列名称移动到列标题。 如何将其应用于多个数据表? 我当前的脚本不起作用。 我有JMP16。 谢谢。
dt_list = Multiple File Import(); //additional known text here to open files
table_script = expr(
//Move the column names listed in row 7 to the column headers
dt = Current Data Table();
dt << clear select;
dt << Clear Column Selection();
lastcol = N Col( dt );
header = 7;
For( i = 1, i <= lastcol, i++,
Column( i ) << set Name( Column(i)[header] )
);
);
Eval(
Eval Expr(
For Each( {value, index},
Expr( dt_list[index] << table_script )
)
)
); 自动化和脚本编写回复:将脚本应用于多个数据表这是我的设置方法
Names Default To Here( 1 );
dt_list = Multiple File Import();
table_script = Function( {dt},
{defaultlocal},
//Move the column names listed in row 7 to the column headers
dt << clear select;
dt << Clear Column Selection();
lastcol = N Col( dt );
header = 7;
For( i = 1, i <= lastcol, i++,
Column( i ) << set Name( Column( i )[header] )
);
);
For Each( {value}, dt_list, table_script( value ) );回复:将脚本应用于多个数据表感谢您的回复! 我尝试了您的脚本,但它仅在打开的最后一个数据表上运行 table_script 函数。 您知道可能出现什么问题吗? 谢谢。
回复:将脚本应用于多个数据表我复制了您指出的发现,但无法使用我正在采取的方法纠正该问题。所以我回到了你的原始代码,并简化了方法并成功运行了一个完整的示例。
Names Default To Here( 1 );
rc = Create Directory( "$TEMP/sub1" );
dt = Open( "$SAMPLE_DATA/big class.jmp" );
Close( dt, save( "$TEMP/sub1/MFI big class.jmp" ) );
dt = Open( "$SAMPLE_DATA/body fat.jmp" );
Close( dt, save( "$TEMP/sub1/MFI body fat.jmp" ) );
dt = Open( "$SAMPLE_DATA/candy bars.jmp" );
Close( dt, save( "$TEMP/sub1/MFI candy bars.jmp" ) );
Show( Files In Directory( "$TEMP/sub1" ) );
dt_list = Multiple File Import(
<<SET folder=""></SET>
回复:将脚本应用于多个数据表太感谢了! 您的新脚本可以对所有打开的数据表进行编辑。 但是,我发现我的脚本未按预期运行,而是将“7”附加到所有列标题,而不是将第 7 行移动为列标题。 它以前适用于单个数据表,但在这种情况下,我需要更改代码以实际读取指定位置中的表值。 这是我的工作代码:
Names Default To Here( 1 );
dt_list = Multiple File Import();
table_script = Expr(
//Move the column names listed in row 7 to the column headers
dt = Current Data Table();
dt << clear select;
dt << Clear Column Selection();
lastcol = N Col( dt );
header = 7;
For( i = 1, i <= lastcol, i++,
tableVal = Column( Current Data Table(), i)[ header ];
Column( i ) << set Name( tableVal )
);
);
For Each( {table}, dt_list,
Current Data Table( table );
table_script;
);