11 which.min(), which.max()和which() which(x, arr.ind = FALSE, useNames = TRUE) x 是一個向量或者數組,可以是NA,但會省略掉,相當於FALSE。 arr.ind = FALSE 當x是數組時,是否返回數組索引(arr.i ...
11--which.min(), which.max()和which()
which(x, arr.ind = FALSE, useNames = TRUE)
- x 是一個向量或者數組,可以是NA,但會省略掉,相當於FALSE。
- arr.ind = FALSE 當x是數組時,是否返回數組索引(arr.ind = array indices)
which(), which.max(), which.min()返回的是位置
> which(2:10 > 3)
[1] 3 4 5 6 7 8 9
> m <- matrix(1:12, 3, 4)
> div.3 <- m %% 3 == 0
> which(div.3)
[1] 3 6 9 12
> which(div.3, arr.ind = TRUE)
row col
[1,] 3 1
[2,] 3 2
[3,] 3 3
[4,] 3 4
> which.max(2:4)
[1] 3