我一直在嘗試從 JMP 表中提取第二大數字。 到目前為止,我只是手動使用
降序排序( Eval List( {:X1, :X2, :X3}));
我怎樣才能只傳遞整個表而不是單個列名?

IF() 函數中的比較組件存在邏輯問題。
If( (Abs( colMax )) > 300 | (Abs( colMax )) > 250
任何大於 250 的值都將使比較為真,因此,不需要 >300。
比較只需要:
If( ( Abs( colMax ) > 250,
你問為什麼你得到 193 的值?這是因為打印出來的值是該列的第二高值,並且您的過濾基於該列中的最大值。第二高的值可以是任何值。如果您在一列中有以下值
最大列值為 600,因此它將通過 Max Col() > 250 的 IF() 子句,列中的第二高值為 193
關於你關於“如何找到第二高值的行號,即 colSecondMaxValues?”,執行此操作的方法已經在腳本中。該聲明
maxRows = dt << get rows where( As Column( dt, colNamesList[i] ) == colMax );
返回列中具有最大值的行的行號矩陣。如果您想要第二個最大值的行號,您只需要獲取它們等於第二個最大值的行。因此,如果您在 Insert Into() 函數之後添加此語句,您將獲得具有第二高值的行
Show(
dt << get rows where(
As Column( dt, colNamesList[i] ) == Col Max( Column( dt, colNamesList[i] ) )
)
);
這是完整的代碼
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );
colNamesList = dt << get column names( string, continuous, numeric );
colSecondMaxValues = {};
// Loop across all continuous columns and find the Max value in
// a column, delete that value, and then find the second max value
// finally, replace the old values, and save the results
For( i = 1, i <= N Items( colNamesList ), i++,
colMax = Col Max( Column( dt, colNamesList[i] ) );
If( Abs( colMax ) > 250,
maxRows = dt << get rows where( As Column( dt, colNamesList[i] ) == colMax );
Show( maxRows );
Column( dt, colNamesList[i] )[maxRows] = .;
Insert Into( colSecondMaxValues, Col Max( Column( dt, colNamesList[i] ) ) );
Show(
dt << get rows where(
As Column( dt, colNamesList[i] ) == Col Max( Column( dt, colNamesList[i] ) )
)
);
Show( colSecondMaxValues );
Column( dt, colNamesList[i] )[maxRows] = colMax;
);
);@txnelson謝謝你的劇本。 我正在嘗試為此腳本設置大於 300 或 250 的條件,但我無法理解為什麼它仍然需要像 193 這樣的值。 另外,如何找到第二高值的行號,即 colSecondMaxValues? 非常感謝您的幫助。
dt=open("$SAMPLE_DATA/semiconductor capability.jmp");
colNamesList= dt<<GET column="" names=""> 300 | (abs(colMax)) > 250,
maxRows = dt<<GET rows="" where=""></GET></GET>如果你想要整個表中的第二大值,不管它在哪一列:
Names default to here(1);
dt = open( "$SAMPLE_DATA/semiconductor capability.jmp" );
//Find the two largest values in the entire table
Sort Descending(Shape(dt << Get all columns as matrix(),1))[{1, 2}];
//Or, to exclude character columns
Sort Descending(Shape(dt << Get as matrix(dt << get column names(numeric)),1))[{1, 2}];這是我編寫的一個小腳本,用於確定數據表中所有連續列的第二高值
names default to here(1);
dt=open("$SAMPLE_DATA/semiconductor capability.jmp");
colNamesList= dt<<GET column="" names=""></GET>