循环查找每个唯一值的最大值你好,
我试图迭代 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提到。