min(which()) 在条件下未检索到正确的数字

min(which()) not retrieving the correct number under condition

我有一个 4 x 600 的数据表,其中包含 3 个数字列,随机整数范围为 0 - 700。我将一个变量定义为一个值为 542 的整数。我正在尝试确定更大的最小值比每个数字列中的 542 都多。但是,以下作品却拉错了价值,知道为什么吗?或者如果我做错了什么?

#data.table called df with numeric columns being b,c,d

a <- as.integer(542)
min(which(df$b > a))
[1] 131

这怎么可能?我知道此列的正确值应该是 543。

which 的输出是一个位置索引,min 应用于 which returns 最小位置而不是最小值的位置。使用 which 的输出提取 'b' 中的值,然后用 min

换行
min(df$b[which(df$b > a)])

你应该知道 which.min 等同于

which(x == min(x, na.rm = TRUE))

而且绝对不同于min(which(x))