将列转换为行
数据和期望的结果
我将衷心感谢您的帮助
质量和工艺工程分享和交流结果回复:将列转置为行的 JSL 脚本谢谢吉姆
回复:将列转置为行的 JSL 脚本我的错误......错误地,我发送给您的最后一个条目没有经过我的修改。 我已编辑了上次回复并更新了 JSL。 请返回并拉取 JSL 并运行它。 现在它包含更正后的代码。回复:将列转置为行的 JSL 脚本谢谢吉姆,但由于某些原因,更新后的脚本我仍然遇到同样的错误

回复:将列转置为行的 JSL 脚本问题在于一个或多个参数作为字符数据输入。Transpose 无法处理混合数据。因此,我添加了一项检查以确保所有检测到的参数都是数字。
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 &
Column( dt, i ) << get modeling type == "Continuous",
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 脚本显示的错误消息表明“dtTrans2”指向的数据表尚未创建。“dtTrans2”是从 Transpose() 创建的,它需要原始数据表中的参数列表。“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 脚本尝试运行第 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
);
查看 Transpose 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 )
)
);
并查看参数ColNamesList是否包含数据表中所有测试的名称。
然后继续检查代码的不同部分,直到找到运行不正确的部分。
如果您可以向我提供您正在尝试读入的数据表的副本,我愿意自己进行检查。
回复:将列转置为行的 JSL 脚本没有日志错误。当我运行脚本时,它什么也没做。唯一的区别是测试名称......它们不同。但所有其他标头都是相同的回复:将列转置为行的 JSL 脚本日志中是否有错误信息?
2个数据表有什么区别?
脚本是否在完成之前停止?
回复:将列转置为行的 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 脚本我正在使用 jmp 14
回复:将列转置为行的 JSL 脚本您使用什么版本的 JMP?回复:将列转置为行的 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 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 );