Rev 5184 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{which}\title{Which indices are TRUE ?}\usage{which(x, arr.ind = FALSE)}\alias{which}\arguments{\item{x}{a \code{\link{logical}} vector or array. \code{\link{NA}}sare allowed and omitted (treated as if \code{FALSE}).}\item{arr.ind}{logical; should \bold{arr}ay \bold{ind}ices be returnedwhen \code{x} is an array?}}\description{Give the \code{TRUE} indices of a logical object,allowing for array indices.}\value{If \code{arr.ind == FALSE} (the default), an integer vector with\code{length} equal to \code{sum(x)}, i.e., to the number of\code{TRUE}s in \code{x}; Basically, the result is\code{(1:length(x))[x]}.If \code{arr.ind == TRUE} and \code{x} is an \code{\link{array}}(has a \code{\link{dim}} attribute), the result is a matrixwho's rows each are the indices of one element of \code{x}; seeExamples below.}\author{Werner Stahel and Peter Holzer \email{holzer@stat.math.ethz.ch},for the array case.}\seealso{\code{\link{Logic}}}\examples{which(LETTERS == "R")which(ll <- c(T,F,T,NA,F,F,T))#> 1 3 7names(ll) <- letters[seq(ll)]which(ll)which((1:12)\%\%2 == 0) # which are even?str(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); mwhich(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(..)) == 1which(vm \%\% 3 == 0, arr.ind=TRUE)}\keyword{logic}\keyword{attribute}