【每天一个R语言命令】-which
2021-02-16 本文已影响0人
肖ano
【描述】
找出你给的参数里逻辑值为TRUE的元素的索引
【用法】
which(x, arr.ind = FALSE, useNames = TRUE)
arrayInd(ind, .dim, .dimnames = NULL, useNames = FALSE)
【参数】
x
a logical vector or array. NAs are allowed and omitted (treated as if FALSE).
arr.ind
logical; should array indices be returned when x is an array?
ind
integer-valued index vector, as resulting from which(x).
.dim
dim(.) integer vector
.dimnames
optional list of character dimnames(.). If useNames is true, to be used for constructing dimnames for arrayInd() (and hence, which(*, arr.ind=TRUE)). If names(.dimnames) is not empty, these are used as column names. .dimnames[[1]] is used as row names.
useNames
logical indicating if the value of arrayInd() should have (non-null) dimnames at all.
【代码】
> x <- seq(1:10)
> x
[1] 1 2 3 4 5 6 7 8 9 10
> which(x != 5)
[1] 1 2 3 4 6 7 8 9 10
> which(c(T,F,T))
[1] 1 3