循環尋找每個唯一值的最大值你好,
我試圖迭代 X 和 Y 的每個值並將最大 rn 值保存在 MaxValue 列中。
這是我嘗試過的,但有些東西似乎不正確。 有什麼建議嗎?
Names Default To Here( 1 );
// Assuming your data table is named 'dt'
dt = Current Data Table();
// Create a new column "MaxValue" and initialize with a large negative number
// Loop through unique Barcode values
// Loop through rows
dt << begin data table();
// Loop through rows
For( i = 1, i <= N Rows( dt ), i++,
currentBarcode = dt:Barcode[i];
// Find the location of the maximum rn value for the current Barcode
maxRNRow = Max( dt:rn[dt:Barcode[i] == currentBarcode] );
// Check if the maxRNRow is not 0 (meaning there is at least one matching Barcode)
If( maxRNRow != 0,
// Update "MaxValue" column with the max rn value for the current Barcode
dt:MaxValue[i] = dt:rn[maxRNRow]
);
);
dt << end data table();
自動化和腳本編寫回覆:循環找出每個唯一值的最大值試試這個吧。
Col Max( :rn, :Y, :X )
編輯
為了更清楚,將 :MaxValue 的公式設定為
Col Max( :rn, :Barcode )
回覆:循環找出每個唯一值的最大值這裡不需要循環。 你可以做什麼@mmarchandTSI建議並將Col Max 與byvar 一起使用,您可以使用Summarize 來計算最大值,然後使用這些值建立新列,或者您可以建立總計表並將其與最大值連接(或更確切地說更新)到表中。 開始/結束訊息也是
dt << Begin Data Update;
dt << End Data Update;
回覆:循環找出每個唯一值的最大值@mmarchandTSI Col max 僅適用於 :Barcode 欄位。 問題是某些表沒有條碼列,因此我嘗試查看是否可以使用 X 和 Y 座標來分配最大 rn 值
回覆:循環找出每個唯一值的最大值您可以新增多個 byvar
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << New Column("Maximum Value for Each Age and Sex Group",
Formula(Col Maximum(:height, :age, :sex))
);

列最大()
回覆:循環找出每個唯一值的最大值是的,所以我發布的第一個公式將適用於你正在做的事情,因為@jthi提到。