\Header{which}{Which indices are TRUE ?}
\keyword{logic}{which}
\keyword{attribute}{which}
\begin{Usage}
\begin{verbatim}
which(x, arr.ind = FALSE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{x}] a logical vector or array.  \texttt{\Link{NA}}s are allowed an omitted.
\item[\texttt{arr.ind}] logical; should \bold{arr}ay \bold{ind}ices be returned
when \texttt{x} is an array?
\end{ldescription}
\end{Arguments}
\begin{Description}
Give the \texttt{TRUE} indices of a logical object,
allowing for array indices.\end{Description}
\begin{Value}
If \texttt{arr.ind == FALSE} (the default), an integer vector with
\texttt{length} equal to \texttt{sum(x)}, i.e., to the number of
\texttt{TRUE}s in \texttt{x}; Basically, the result is
\texttt{(1:length(x))[x]}.

If \texttt{arr.ind == TRUE} and \texttt{x} is an \texttt{\Link{array}}
(has a \texttt{\Link{dim}} attribute), the result is a matrix
who's rows each are the indices of one element of \texttt{x}; see
Examples below.\end{Value}
\begin{Author}
Werner Stahel and Peter Holzer \email{holzer@stat.math.ethz.ch},
for the array case.\end{Author}
\begin{SeeAlso}
\texttt{\Link{Logic}}\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
which(LETTERS == "R")
which(c(T,F,T,NA,F,F,T))#> 1 3 7
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); 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)
\end{ExampleCode}
\end{Examples}

