我正在尝试将选定行的列值拉入连接标签中,该标签用于注释分布中添加的参考线。
连接中的错误消息是由于列表维度不匹配造成的。用于从选定行收集值的关联数组调用正在删除重复值,从而产生唯一值列表。
我的目标是将给定选定行的姓名、年龄和体重放入一个字符串中,以便在以后的添加引用调用中用作标签。
使用当前的方法,我有错误代码,并且在某些情况下,数据错位而没有错误代码。
示例 1 - 错误条件:找到三个唯一权重,其中年龄和姓名列表仅从所选行中找到两个项目。由于列表维度的差异,索引的第三次迭代失败。
示例 2 - 数据错位:使用姓名 Leslie 和 Patty 选择了三行。有两个条目名为 Patty,一个年龄 14 岁,体重 85,另一个年龄 16 岁,体重 134。Patty 的条目之一和 Leslie 的条目都是 14 岁。如果标签仅考虑姓名 {“LESLIE”、“PATTY”} 和年龄 {14,16} 的列表,则可以看到数据错位的结果。索引只会生成两个条目,第一个是“Leslie ...14”,第二个是“Patty ...16”,这是一个正确的关联,但“Patty ...14”被遗漏,并且列表维度依赖于数据。
我是否应该删除关联数组调用并转而采用子集/表方法,或者我是否应该修改关联数组调用以获得列表项,这些列表项是每次迭代或每个选定行捕获的姓名、年龄和体重的列表?
谢谢你,
布莱恩
列表尺寸超出时的错误代码:
参数应为访问或评估“Concat”时第 41 行的字符,错误参数(theAges[i]),theNames[i] || /*###*/" ..." || /*###*/theAges[i] /*###*/

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
col_name_list = dt << get column names( string );
newColName = "State";
// New column: State
If( !Contains( col_name_list, newColName ),
Local( {dt, tempStrings},
dt = Data Table( "Big Class" );
dt << New Column( "State", Character, "Nominal" ) << Begin Data Update;
tempStrings = {"CA", "WA", "OR"};
For Each Row( dt, :State = tempStrings[Sequence( 1, 3, 1, 1 )] );
dt << End Data Update;
);
//Make it a double Patty :), another person with the same name.
dt << Add Rows( 1, At End );
//Cheat and use a constant of 41 for the last row index
dt[[41], {name, age, sex, height, weight, State}] = {{"PATTY", 16, "F", 57, 134, "WA"}};
);
// For illustration, select some names
dt << select where( Contains Item( :name, {"LESLIE", "PATTY"} ) );
dist = dt << Distribution(
Stack( 1 ),
Continuous Distribution(
Column( :height ),
Quantiles( 0 ),
Summary Statistics( 0 ),
Horizontal Layout( 1 ),
Normal Quantile Plot( 0 ), // disable, if the user enabled it in the preferences :)
Vertical( 0 ),
Set Bin Width( 2 ),
Process Capability( 0 )
//);
),
By( :State )
);
// get all reports
// if there is a BY group, get the info - if there is none, put it into a list
If( Is List( dist ),
dists=dist;
myBys = Transform each ({myexpr} , dist << Get Where Expr, Arg(myExpr , 2 ))
, //no By
dists = Eval List( {dist} );
myBys= {};
);
//get the reports
distRPTs = Transform Each( {dist}, dists, Report( dist ) );
// Find the Midpoints of the bins the selected rows are in
dist << Save( "Level Midpoints" );
//loop though the By groups and add the reflines
For Each( {report, idx}, distRPTs,
//report = distRPTs[2]; idx=2;
selected rows = dt << get selected rows;
// there is a BY group -> restrict the selection
if(N Items(myBys),
Eval( Eval Expr( selected rows = dt << get rows where( Contains( Expr( selected rows ), Row() ) & :State == Expr( myBys[idx] ) ) ) );
);
theBins = (Associative Array( Column( dt, N Cols( dt ) )[selected rows] )) << get keys;
theNames = (Associative Array( Column(dt, "name") [dt << get selected rows] )) << get keys;
theAges = (Associative Array( Column(dt, "age") [dt << get selected rows] )) << get keys;
theWeights = (Associative Array( Column(dt, "weight") [dt << get selected rows] )) << get keys;
For( i = 1, i <= N Items(theWeights), i++,
theLabels[i] = theNames[i] || " ..." || theAges[i] ;
);
);
dt << delete columns( N Cols( dt ) );嗨,布莱恩,您可以使用转换列来准备正确的结果 - 然后选择您需要的条目:

查看更多...Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
col_name_list = dt << get column names( string );
newColName = "State";
// New column: State
If( !Contains( col_name_list, newColName ),
Local( {dt, tempStrings},
dt = Data Table( "Big Class" );
dt << New Column( "State", Character, "Nominal" ) << Begin Data Update;
tempStrings = {"CA", "WA", "OR"};
For Each Row( dt, :State = tempStrings[Sequence( 1, 3, 1, 1 )] );
dt << End Data Update;
);
//Make it a double Patty :), another person with the same name.
dt << Add Rows( 1, At End );
//Cheat and use a constant of 41 for the last row index
dt[[41], {name, age, sex, height, weight, State}] = {{"PATTY", 16, "F", 57, 134, "WA"}};
);
// For illustration, select some names
dt << select where( Contains Item( :name, {"LESLIE", "PATTY"} ) );
dist = dt << Distribution(
Stack( 1 ),
Continuous Distribution(
Column( :height ),
Quantiles( 0 ),
Summary Statistics( 0 ),
Horizontal Layout( 1 ),
Normal Quantile Plot( 0 ), // disable, if the user enabled it in the preferences :)
Vertical( 0 ),
Set Bin Width( 2 ),
Process Capability( 0 )
//);
),
By( :State )
);
// get all reports
// if there is a BY group, get the info - if there is none, put it into a list
If( Is List( dist ),
dists=dist;
myBys = Transform each ({myexpr} , dist << Get Where Expr, Arg(myExpr , 2 ))
, //no By
dists = Eval List( {dist} );
myBys= {};
);
//get the reports
distRPTs = Transform Each( {dist}, dists, Report( dist ) );
// Find the Midpoints of the bins the selected rows are in
dist << Save( "Level Midpoints" );
dt << transform column ("label",Character, Formula (:name || " ..." || Char(age)));
//loop though the By groups and add the reflines
For Each( {report, idx}, distRPTs,
//report = distRPTs[2]; idx=2;
selected rows = dt << get selected rows;
// there is a BY group -> restrict the selection
if(N Items(myBys),
Eval( Eval Expr( selected rows = dt << get rows where( Contains( Expr( selected rows ), Row() ) & :State == Expr( myBys[idx] ) ) ) );
);
myLabels = Associative Array(:label[selected rows]) << get keys;
print(myLabels)
);
dt << delete columns( N Cols( dt ) );
嗨@hogi
我已将您的想法结合在这篇文章和有关添加参考线的相关文章中。
该解决方案能够在不丢失重复值的情况下对齐正确的信息,同时正确地将箱子添加到堆栈中的图中,它是通过嵌套 for 循环中选定的行进行索引,从表中的字段中准备列表。
- 绘制分布
- 根据标准将报告中实例中的每个图收集到一个数组中(每个数据项 3 个图,3 个数组)
- 将报告收集到迭代使用的对象中
- 附加绘制数据的中点(3 个图,3 列附加到数据表)
- 使用 For Each 循环遍历对象来访问和扩充每个图
- 初始化箱子和标签的列表变量
- 根据基线标准(例如序列号)选择数据中的行
- 根据图中符合条件的标准来优化选定的行
- 使用 for 循环来选择尽可能多的行
- 从附加的中点列收集箱子(每个图都有相应的列)
- 将有趣的列中的信息收集到标签中(例如测量日期、序列号)
- 添加包含收集到的信息的参考行。
- 删除中点列,以避免在步骤 1 中的绘图设置发生变化时出现过时的数据。
有帮助的关键变化:
1. 从关联数组更改为通过迭代填充的列表,以避免消除重复的值并保持一致。
2. 为每个条件创建单独的变量。
希望这有助于形成循环。感谢您的建议。它们促进了我的学习和进步。