|
m=c("a","b","c","b","c","b","b","a","c","b","c","a")
想知道其中b所处位置的所有下标
方法:
which(m=="b")
大家可以参考which函数说明
http://www.biostatistic.net/thread-7319-1-1.html
中文文档帮助说明
http://cos.name/cn/topic/103273#post-212597
cos论坛上关于y[which(x>a)] 与 y[x>a]有区别吗? 的说明
which(x, arr.ind = FALSE, useNames = TRUE)
arrayInd(ind, .dim, .dimnames = NULL, useNames = FALSE)
还有这些例子也可以帮助理解
which(LETTERS == "R")
which(ll <- c(TRUE,FALSE,TRUE,NA,FALSE,FALSE,TRUE))#> 1 3 7
names(ll) <- letters[seq(ll)]
which(ll)
which((1:12)%%2 == 0) # which are even?
which(1:10 > 3, arr.ind=TRUE)
( m <- matrix(1:12,3,4) )
which(m %% 3 == 0)
which(m %% 3 == 0, arr.ind=TRUE)
rownames(m) <- paste("Case",1:3, sep="_")
which(m %% 5 == 0, arr.ind=TRUE)
dim(m) <- c(2,2,3); m
which(m %% 3 == 0, arr.ind=FALSE)
which(m %% 3 == 0, arr.ind=TRUE)
vm <- c(m)
dim(vm) <- length(vm) #-- funny thing with length(dim(...)) == 1
which(vm %% 3 == 0, arr.ind=TRUE)
|
|