跨多列的每行最大值以及來源列對應的名稱你好,有沒有簡單的方法可以找到每行的最大值以及最大值對應的列名(或參數)? 以下是一個簡單的範例來說明請求:
| T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10 | 最大值 | Col_Name(參數) |
| 87.2 | 83.6 | 81.4 | 83 | 83 | 83 | 83 | 82.3 | 83.3 | 84.6 | 87.2 | T1 |
| 85.9 | 84 | 82 | 84 | 83.3 | 83.3 | 84 | 83 | 86.5 | 87.2 | 87.2 | T10 |
| 84.9 | 82.7 | 86 | 83 | 82.3 | 82.3 | 83 | 82 | 83.6 | 85.2 | 86 | T3 |
| 85.6 | 84.6 | 82.7 | 84.6 | 84.3 | 84.3 | 84.3 | 83.6 | 84.9 | 86.2 | 86.2 | T10 |
| 85.2 | 83.6 | 82 | 83.3 | 83 | 83 | 83.3 | 82.3 | 84.3 | 85.6 | 85.6 | T10 |
| 86.8 | 84.3 | 82.7 | 84.3 | 83.6 | 83.6 | 84.3 | 83.3 | 85.9 | 86.2 | 86.8 | T1 |
| 86.2 | 84 | 82.3 | 84 | 87 | 83.3 | 83.6 | 83 | 84.9 | 85.9 | 87 | T5 |
| 88.1 | 84.6 | 82.3 | 84.3 | 83.6 | 84 | 84.3 | 83.3 | 85.9 | 86.2 | 88.1 | T1 |
| 85.6 | 83.3 | 81.7 | 83.3 | 83 | 83 | 83.6 | 82.7 | 84 | 85.9 | 85.9 | T10 |
| 37.4 | 36.1 | 36.4 | 36.4 | 36.1 | 36.1 | 36.4 | 35.4 | 36.7 | 37.4 | 37.4 | T1 |
| 36.7 | 34.5 | 34.8 | 34.5 | 33.8 | 34.1 | 34.5 | 33.5 | 36.1 | 36.1 | 36.7 | T1 |
| 34.8 | 32.9 | 33.2 | 32.9 | 32.2 | 32.5 | 36 | 31.9 | 33.8 | 35.1 | 36 | T7 |
| 38 | 36.4 | 36.4 | 36.4 | 36.4 | 36.1 | 36.7 | 39 | 38 | 38.3 | 39 | T8 |
| 38 | 35.1 | 35.1 | 40 | 34.1 | 34.5 | 34.8 | 33.8 | 36.4 | 37 | 40 | T4 |
謝謝!
回覆:跨多列的每一行的最大值以及來源列的對應名稱我一開始誤讀了你的問題......所以這個答案包含一個簡化,不使用替代品,以及尋找特定值的變體。
dt = New Table( "Untitled",
Add Rows( 3 ),
New Column( "first", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 5, 9] ) ),
New Column( "second", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 6, 10] ) ),
New Column( "skip", character, setvalues( {"a", "b", "c"} ) ),
New Column( "third", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 7, 11] ) ),
New Column( "fourth", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 8, 12] ) )
);
names = dt << getcolumnnames( "numeric" ); // returns a list of all numeric column names
findval=7;
row = 2;
Row() = row; // names will pull data from the current row
rowpos = Loc( findval==matrix(evallist(names)) );
show(names[rowpos],names[rowpos[1]][row]);
names[rowpos] = {:third};
names[rowpos[1]][2] = 7;
Loc 傳回矩陣中非零項的位置。 帶有標量和矩陣的 == 運算子傳回一個由 1 和 0 組成的矩陣。 Loc 函數傳回 rowpos 中的矩陣(帶有 1 的索引); [1] 採用與 findval 相符的第一個位置。 name[rowpos[1]] 是列名,[row] 從列的行中取得符合的答案。
回覆:跨多列的每一行的最大值以及來源列的對應名稱謝謝克雷格!
除了 Concat() 之外,還有其他函數可以與 Substitute Into() 一起使用來尋找跨多列的行中特定值的位置嗎?
dt = New Table( "Untitled",
Add Rows( 3 ),
New Column( "first", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 5, 9] ) ),
New Column( "second", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 6, 10] ) ),
New Column( "skip", character, setvalues( {"a", "b", "c"} ) ),
New Column( "third", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 7, 11] ) ),
New Column( "fourth", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 8, 12] ) )
);
names = dt << getcolumnnames( "numeric" ); // returns a list of all numeric column names
Show( names ); // {first, second, third, fourth}
Substitute Into( names, Expr( {} ), Expr( Concat() ) );
Show( Name Expr( names ) ); // first || second || third || fourth
Row() = 2; // names will pull data from the current row
rowpos = Loc( names, 6 ); // works only with a list
謝謝,
拉維
回覆:跨多列的每一行的最大值以及來源列的對應名稱(尋找 IFMax...)是的,如果您可以輕鬆列出列,那麼解釋會更容易。 可能也更快。 感謝您指出!
回覆:跨多列的每一行的最大值以及來源列的對應名稱在新列中使用 IFMax 函數有什麼問題嗎?我意識到,如果列數很大,這會很不方便,但如果只有 20 列或更少,則只需輸入 IFMax 公式就非常簡單。
回覆:跨多列的每一行的最大值以及來源列的對應名稱資料表下標是 JMP 13 中的新增功能。
您可以嘗試類似的想法來建立一個表達式,該表達式將在評估時從當前行建立行向量矩陣。
dt = New Table( "Untitled",
Add Rows( 3 ),
New Column( "first", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 5, 9] ) ),
New Column( "second", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2, 6, 10] ) ),
New Column( "skip", character, setvalues( {"a", "b", "c"} ) ),
New Column( "third", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 7, 11] ) ),
New Column( "fourth", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4, 8, 12] ) )
);
names = dt << getcolumnnames( "numeric" ); // returns a list of all numeric column names
Show( names ); // {first, second, third, fourth}
Substitute Into( names, Expr( {} ), Expr( Concat() ) );
Show( Name Expr( names ) ); // first || second || third || fourth
Row() = 2; // names will pull data from the current row
rowvec = (Eval( names )); // [5 6 7 8]
給定行名稱列表,Substitute Into() 函數用 concat 函數取代大括號列表運算子。 Concat 函數與 || 相同連接運算子 and 可以帶很多參數。 此串聯計算目前行的列表中的每個列引用。 各個標量值連接成行矩陣。
回覆:跨多列的每一行的最大值以及來源列的對應名稱嗨克雷格,
當我在 JMP 10 中執行範例腳本時,收到一條錯誤訊息,指出 - 在存取或評估「Loc Max」時,參數應該是矩陣{1},錯誤參數...
JMP10 中不允許資料表索引嗎?
謝謝!
回覆:跨多列的每一行的最大值以及來源列的對應名稱好吧,我錯過了一些東西......附件是我的輸出。 當我檢查結果時,列 MaxVal 包含在該行第 3-25 列中找到的最大值,而 MaxVal_Col 是找到最大值的列的名稱。
我缺什麼?
回覆:跨多列的每一行的最大值以及來源列的對應名稱再次感謝吉姆! 但是,如果您檢查輸出,我想您會發現它不正確。
回覆:跨多列的每一行的最大值以及來源列的對應名稱好吧......我的錯誤,我以為你無法讓程式碼運行,而不是你得到了無效的結果。 問題是您的列清單「colnames」與您正在執行 Loc Max 的列清單不符。 需要從“colname”清單中刪除第一和第二列名稱。 此問題也導致使用以下語句取得 MaxVal 時出現問題:
MaxVal = dt[r, 位置];
因為它將查看整個資料表,並且它返回的位置基於一個比資料表少 2 列的矩陣。
所以我做了一個簡單的重寫,展示了解決這個問題的一種方法
dt = Open( "C:/data.jmp" );
colnames = dt << getcolumnnames;
For( i = 2, i >= 0, i--,
colnames = Remove( colnames, i, 1 )
);
For Each Row(
r = Row();
location = Loc Max( dt[r, 3 :: 25] ); // location of maximum value in array from Col #3 to #25
//MaxVal = dt[r, location];
MaxVal_Col = colnames[location] << getname;
MaxVal = as column(eval(MaxVal_Col));
);
回覆:跨多列的每一行的最大值以及來源列的對應名稱謝謝吉姆! 這就是我得到的結果,但輸出不正確,例如,第 1 行和第 2 行。
回覆:跨多列的每一行的最大值以及來源列的對應名稱謝謝吉姆! 這就是我得到的結果,但輸出不正確,例如,第 1 行和第 2 行。
回覆:跨多列的每一行的最大值以及來源列的對應名稱我看到一些錯誤,懷疑是因為快取造成的。 我解決這些問題的唯一方法是重新啟動我的作業系統,而不是 JMP 本身。
您可以在重新啟動作業系統後執行更新的腳本並檢查嗎?
回覆:跨多列的每一行的最大值以及來源列的對應名稱這是我運行腳本後的數據表
回覆:跨多列的每一行的最大值以及來源列的對應名稱非常感謝吉姆的回覆! 但是,它仍然對我不起作用dt=當前資料表()。 不知道發生了什麼事。 順便說一句,你能把你產生的輸出檔寄給我嗎?
謝謝!
回覆:跨多列的每一行的最大值以及來源列的對應名稱腳本和數據表對我來說非常有用。現在,我確實改變了
dt=Open("........");
到
dt=current data table();
因為桌子已經開著了。
因此,我建議您嘗試這樣做,或者在 dt=Open 語句之後添加一個附加語句:
wait(0);
在 For Each Row 開始之前,您的資料表可能尚未完成。等待(0);將在運行 For Each Row 之前強制打開完成
回覆:跨多列的每一行的最大值以及來源列的對應名稱它對我來說仍然不能正常工作。 請在附件中找到腳本和資料檔案。 你能讓我知道我在這裡做錯了什麼嗎?
謝謝!
回覆:跨多列的每一行的最大值以及來源列的對應名稱好點子。 這個例子可以這樣概括(故意醜陋的列排列......) 選擇最適合您的其中之一。 第二個優點是可以避免列的意外重新排列。 第一個可能適合數百列。
dt = New Table( "Untitled",
New Column( "maxval", numeric ),
New Column( "a", Numeric, Set Values( [1, 33, 1] ) ),
New Column( "maxcol", Numeric ),
New Column( "b", Numeric, Set Values( [2, 2, 2] ) ),
New Column( "c", Numeric, Set Values( [333, 1, 0] ) ),
);
// either
vars = [2 4 5];
colnames = (dt << getcolumnnames)[vars];
// or
colnames={a,b,c}; // this might be best choice
For Each Row(
row = Row();
location = Loc Max( dt[ row, colnames] ); // location of maximum value in array
col = colnames[location]<<GETNAME></GETNAME>回覆:跨多列的每一行的最大值以及來源列的對應名稱解決了我缺少必須添加到位置變數的列的偏移量。
回覆:跨多列的每一行的最大值以及來源列的對應名稱我在這裡遇到了一個問題,如果我需要選擇的列位於資料集之間,那麼它似乎不起作用。
For Each Row(
r = Row();
// 1::3 means columns 1 through 3. {a,b,c} would also work.
location = Loc Max( dt[ r, 57 :: 113] ); // location of maximum value in array
maxval = dt[r, location];
maxcol = colnames[location] << getname;
);
我需要選擇第 57 列到第 113 列,但由於某種原因,當我透過腳本執行此操作時,我得到了不正確的值。
回覆:跨多列的每一行的最大值以及來源列的對應名稱// this example uses JMP 13 data table indexing
dt = New Table( "Untitled",
New Column( "a", Numeric, Set Values( [1, 33, 1] ) ),
New Column( "b", Numeric, Set Values( [2, 2, 2] ) ),
New Column( "c", Numeric, Set Values( [333, 1, 0] ) ),
New Column( "maxval", numeric ),
New Column( "maxcol", Numeric )
);
colnames = dt << getcolumnnames;
For Each Row(
r = Row();
// 1::3 means columns 1 through 3. {a,b,c} would also work.
location = Loc Max( dt[ r, 1 :: 3] ); // location of maximum value in array
maxval = dt[r, location];
maxcol = colnames[location] << getname;
);
Data table with maximum value from row and name of maximum column for rowData table with maximum value from row and name of maximum column for row具有行中最大值和行中最大列名稱的資料表
之前關於數據表下標的文章
回覆:跨多列的每一行的最大值以及來源列的對應名稱尋找完全相同的解決方案。
對於每一行,找到最大值並傳回列名稱,以便我可以對結果資料進行統計。
例如,查找列名顯示為最大值的次數、貢獻最大值的列數、STD DEV 等。