我試圖將選定行的列值拉入串聯標籤,該標籤用於註釋分佈中新增的參考線。
連線中的錯誤訊息是由於清單維度不匹配造成的。用於從所選行收集值的關聯數組呼叫會刪除重複值,從而產生唯一值的清單。
我的目標是將給定選定行的名稱、年齡和體重放入一個字串中,該字串可以在稍後的新增引用呼叫中用作標籤。
使用目前的方法,我有錯誤代碼,在某些情況下,資料未對齊而沒有錯誤代碼。
範例 1 - 錯誤條件:找出三個唯一的權重,其中年齡和姓名清單僅在所選行中各找到兩項。由於列表維度的差異,索引的第三次迭代失敗。
範例 2 - 資料未對齊:使用 Leslie 和 Patty 名稱選擇了三行。有兩個名為 Patty 的條目,一個年齡 14,體重 85,另一個年齡 16,體重 134。如果標籤僅考慮姓名 {"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 循環物件以存取和擴充每個圖
- 初始化 bin 和標籤的列表變數
- 根據基準標準(例如序號)選擇資料中的行
- 根據與圖中「按」條件相符的條件細化選定的行
- 對盡可能多的選定行使用 for 循環
- 從附加的中點列收集垃圾箱(每個圖都有各自的列)
- 將感興趣的欄位中的資訊收集到標籤中(例如測量日期、序號)
- 新增包含收集資訊的參考線。
- 刪除中點列以避免步驟 1 中的繪圖設定發生變更時資料過時。
有助於的關鍵變化:
1. 從關聯數組變更為透過迭代填入的列表,以避免消除重複值,保持對齊。
2. 為每個 by 條件建立單獨的變數。
希望這有助於關閉循環。感謝您的建議。他們使我的學習和進步得以實現。