【每天一个R语言命令】-which

【描述】

找出你给的参数里逻辑值为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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容