JSL脚本将列转置为行我不确定如何开始,我想要一个脚本的帮助,该脚本会自动将特定选择的列转置为行。
我知道如何手动执行此操作,但我需要一个脚本,因为这是数百个数据文件的非常重复的任务
请参阅附件的jmp文件以获取数据示例和所需结果
我将衷心感谢您的帮助
数据表脚本编写回复:JSL脚本将列转置为行以下脚本是创建所需输出表的良好起点
Names Default To Here( 1 );
dt = Current Data Table();
// Transpose the Demographics
dtTrans1 = dt << Transpose(
columns( :SBIN, :HBIN, :Alarms, :Device, :Site ),
Transpose selected rows only( 1 ),
Output Table( "Transpose 1" )
);
// Change the name of the first column
dtTrans1:Label << set name( "Column 1" ) << Set Display Width( 150 );
// Change the new column names
For( i = 2, i <= N Cols( dtTrans1 ), i++,
Column( dtTrans1, i ) << set name( "Column " || Char( i + 4 ) ) << Set Display Width( 100 )
);
// Change the detail name of the Alarms
dtTrans1:Column 1[(dtTrans1 << get rows where( dtTrans1:Column 1 == "Alarms" ))[1]] = "Pass/Fail/Alarm";
// Create the Devce values
deviceRow = (dtTrans1 << get rows where( dtTrans1:Column 1 == "Device" ))[1];
For( i = 2, i <= N Cols( dtTrans1 ), i++,
Column( dtTrans1, i )[deviceRow] = i - 1
);
// Now Find all of the columns that are parameters
parameterColNamesList = {};
For( i = 1, i <= N Cols( dt ), i++,
If( Is Missing( Num( Word( 1, Column( dt, i ) << get name, ":" ) ) ) == 0,
Insert Into( parameterColNamesList, Column( dt, i ) << get name )
)
);
// Transpose the parameter columns
dtTrans2 = dt << Transpose(
columns( Eval( parameterColNamesList ) ),
Transpose selected rows only( 0 ),
Output Table( "Transpose 2" )
);
// Add in the new columns to be created
dtTrans2 << Add Multiple Columns( "Column", 5, before first, Character );
// Add the values to the new columns
For( i = 1, i <= N Rows( dtTrans2 ), i++,
dtTrans2:Column 1[i] = Word( 1, dtTrans2:Label[i], ":" );
dtTrans2:Column 2[i] = Word( 2, dtTrans2:Label[i], ":" );
specs = Column( dt, dtTrans2:Label[i] ) << get property( "spec limits" );
If( Is Missing( specs["LSL"] ) == 0,
dtTrans2:Column 3[i] = specs["LSL"]
);
If( Is Missing( specs["USL"] ) == 0,
dtTrans2:Column 4[i] = specs["USL"]
);
If( Column( dt, dtTrans2:Label[i] ) << get property( "Units" ) != "",
dtTrans2:Column 5[i] = Column( dt, dtTrans2:Label[i] ) << get property( "Units" )
);
);
// Get rid of the label column which is no longer needed
dtTrans2 << delete columns( :Label );
// Change the names of the Trans2 table to match the names in the Trans1 table
For( i = 6, i <= N Cols( dtTrans2 ), i++,
Column( dtTrans2, i ) << set name( "Column " || Char( i ) )
);
// Combine the 2 Transformed data tables
dtFinal = dtTrans1 << concatenate( dtTrans2 );
// Cleanup the no longer needed data tables
close( dtTrans1, nosave );
close( dtTrans2, nosave );回复:JSL脚本将列转置为行谢谢!这似乎很好。 但是由于某种原因,测试名称Lo Limit和Hi Limit列放在最后。有什么办法可以重新排列它们并在脚本中标记它们?

回复:JSL脚本将列转置为行您正在使用什么版本的JMP?回复:JSL脚本将列转置为行我正在使用jmp 14
回复:JSL脚本将列转置为行这是脚本的更正版本,它将规范列等放置在正确的位置,并且还添加了列标签
Names Default To Here( 1 );
dt = Current Data Table();
// Transpose the Demographics
dtTrans1 = dt << Transpose(
columns( :SBIN, :HBIN, :Alarms, :Device, :Site ),
Transpose selected rows only( 1 ),
Output Table( "Transpose 1" )
);
// Change the name of the first column
dtTrans1:Label << set name( "Column 1" ) << Set Display Width( 150 );
// Change the new column names
For( i = 2, i <= N Cols( dtTrans1 ), i++,
Column( dtTrans1, i ) << set name( "Column " || Char( i + 4 ) ) << Set Display Width( 100 )
);
// Change the detail name of the Alarms
dtTrans1:Column 1[(dtTrans1 << get rows where( dtTrans1:Column 1 == "Alarms" ))[1]] = "Pass/Fail/Alarm";
// Create the Devce values
deviceRow = (dtTrans1 << get rows where( dtTrans1:Column 1 == "Device" ))[1];
For( i = 2, i <= N Cols( dtTrans1 ), i++,
Column( dtTrans1, i )[deviceRow] = i - 1
);
// Now Find all of the columns that are parameters
parameterColNamesList = {};
For( i = 1, i <= N Cols( dt ), i++,
If( Is Missing( Num( Word( 1, Column( dt, i ) << get name, ":" ) ) ) == 0,
Insert Into( parameterColNamesList, Column( dt, i ) << get name )
)
);
// Transpose the parameter columns
dtTrans2 = dt << Transpose(
columns( Eval( parameterColNamesList ) ),
Transpose selected rows only( 0 ),
Output Table( "Transpose 2" )
);
// Add in the new columns to be created
dtTrans2 << Add Multiple Columns( "Column", 5, before first, Character );
// Add the columns 2-5 in the trans data table
dtTrans1 << Add Multiple Columns( "xColumn", 4,after(:Column 1), Character );
for(i=2,i<=5,i++,
column(dtTrans1,i)<<SET name=""></SET>回复:JSL脚本将列转置为行谢谢吉姆!格式完美。但是由于某种原因,它不能与其他类似的数据集一起使用。有什么原因吗?
回复:JSL脚本将列转置为行日志中是否有任何错误消息?
2个数据表之间有什么区别?
脚本在完成之前就停止了吗?
回复:JSL脚本将列转置为行没有日志错误。当我运行脚本时,它什么都不做。唯一的区别是测试名称...它们是不同的。但所有其他标头都相同回复:JSL脚本将列转置为行尝试运行第1行到第26行的代码。所有您需要做的就是选择(突出显示)脚本中的那些行,然后单击“运行”图标。
Names Default To Here( 1 );
dt = Current Data Table();
// Transpose the Demographics
dtTrans1 = dt << Transpose(
columns( :SBIN, :HBIN, :Alarms, :Device, :Site ),
Transpose selected rows only( 1 ),
Output Table( "Transpose 1" )
);
// Change the name of the first column
dtTrans1:Label << set name( "Column 1" ) << Set Display Width( 150 );
// Change the new column names
For( i = 2, i <= N Cols( dtTrans1 ), i++,
Column( dtTrans1, i ) << set name( "Column " || Char( i + 4 ) ) << Set Display Width( 100 )
);
// Change the detail name of the Alarms
dtTrans1:Column 1[(dtTrans1 << get rows where( dtTrans1:Column 1 == "Alarms" ))[1]] = "Pass/Fail/Alarm";
// Create the Devce values
deviceRow = (dtTrans1 << get rows where( dtTrans1:Column 1 == "Device" ))[1];
For( i = 2, i <= N Cols( dtTrans1 ), i++,
Column( dtTrans1, i )[deviceRow] = i - 1
);
查看“转置1”数据表是否如下所示:

30-35行
parameterColNamesList = {};
For( i = 1, i <= N Cols( dt ), i++,
If( Is Missing( Num( Word( 1, Column( dt, i ) << get name, ":" ) ) ) == 0,
Insert Into( parameterColNamesList, Column( dt, i ) << get name )
)
);
并查看parameterColNamesList是否包含数据表中所有测试的名称。
然后继续检查代码的不同部分,直到找到运行不正常的地方。
如果您可以向我提供您要读取的数据表的副本,我将愿意自己进行检查。
回复:JSL脚本将列转置为行确定在这里
回复:JSL脚本将列转置为行这是一个随机样本数据
回复:JSL脚本将列转置为行忽略先前的样本,请使用此样本
回复:JSL脚本将列转置为行这是一个
回复:JSL脚本将列转置为行问题是输入了一个或多个参数作为字符数据。转置不能处理混合数据。因此,我添加了一项检查以确保所有检测到的参数都是数字。
Names Default To Here( 1 );
dt = Current Data Table();
// Transpose the Demographics
dtTrans1 = dt << Transpose(
columns( :SBIN, :HBIN, :Alarms, :Device, :Site ),
Transpose selected rows only( 1 ),
Output Table( "Transpose 1" )
);
// Change the name of the first column
dtTrans1:Label << set name( "Column 1" ) << Set Display Width( 150 );
// Change the new column names
For( i = 2, i <= N Cols( dtTrans1 ), i++,
Column( dtTrans1, i ) << set name( "Column " || Char( i + 4 ) ) << Set Display Width( 100 )
);
// Change the detail name of the Alarms
dtTrans1:Column 1[(dtTrans1 << get rows where( dtTrans1:Column 1 == "Alarms" ))[1]] = "Pass/Fail/Alarm";
// Create the Devce values
deviceRow = (dtTrans1 << get rows where( dtTrans1:Column 1 == "Device" ))[1];
For( i = 2, i <= N Cols( dtTrans1 ), i++,
Column( dtTrans1, i )[deviceRow] = i - 1
);
// Now Find all of the columns that are parameters
parameterColNamesList = {};
For( i = 1, i <= N Cols( dt ), i++,
If( Is Missing( Num( Word( 1, Column( dt, i ) << get name, ":" ) ) ) == 0,
Insert Into( parameterColNamesList, Column( dt, i ) << get name )
)
);
// Transpose the parameter columns
dtTrans2 = dt << Transpose(
columns( Eval( parameterColNamesList ) ),
Transpose selected rows only( 0 ),
Output Table( "Transpose 2" )
);
// Add in the new columns to be created
dtTrans2 << Add Multiple Columns( "Column", 5, before first, Character );
// Add the columns 2-5 in the trans data table
dtTrans1 << Add Multiple Columns( "xColumn", 4,after(:Column 1), Character );
for(i=2,i<=5,i++,
column(dtTrans1,i)<<SET name=""></SET>回复:JSL脚本将列转置为行谢谢吉姆,但由于某些原因我仍然与更新的脚本有相同的错误

回复:JSL脚本将列转置为行我的错误....由于错误,我发送给您的最后一个条目没有我的修改。 我已经编辑了我的最新回复并更新了JSL。 请返回并拉出JSL并运行它。 现在,它包含更正的代码。