\HeaderA{Views-utils}{Utility functions and numeric summary of Views of numerics}{Views.Rdash.utils}
\aliasA{slice}{Views-utils}{slice}
\aliasA{slice,integer-method}{Views-utils}{slice,integer.Rdash.method}
\aliasA{slice,Rle-method}{Views-utils}{slice,Rle.Rdash.method}
\aliasA{slice,RleList-method}{Views-utils}{slice,RleList.Rdash.method}
\aliasA{slice,XInteger-method}{Views-utils}{slice,XInteger.Rdash.method}
\aliasA{viewApply}{Views-utils}{viewApply}
\aliasA{viewApply,RleViews-method}{Views-utils}{viewApply,RleViews.Rdash.method}
\aliasA{viewApply,RleViewsList-method}{Views-utils}{viewApply,RleViewsList.Rdash.method}
\aliasA{viewApply,Views-method}{Views-utils}{viewApply,Views.Rdash.method}
\aliasA{viewMaxs}{Views-utils}{viewMaxs}
\aliasA{viewMaxs,RleViews-method}{Views-utils}{viewMaxs,RleViews.Rdash.method}
\aliasA{viewMaxs,RleViewsList-method}{Views-utils}{viewMaxs,RleViewsList.Rdash.method}
\aliasA{viewMaxs,XIntegerViews-method}{Views-utils}{viewMaxs,XIntegerViews.Rdash.method}
\aliasA{viewMeans}{Views-utils}{viewMeans}
\aliasA{viewMeans,RleViews-method}{Views-utils}{viewMeans,RleViews.Rdash.method}
\aliasA{viewMeans,RleViewsList-method}{Views-utils}{viewMeans,RleViewsList.Rdash.method}
\aliasA{viewMeans,XIntegerViews-method}{Views-utils}{viewMeans,XIntegerViews.Rdash.method}
\aliasA{viewMins}{Views-utils}{viewMins}
\aliasA{viewMins,RleViews-method}{Views-utils}{viewMins,RleViews.Rdash.method}
\aliasA{viewMins,RleViewsList-method}{Views-utils}{viewMins,RleViewsList.Rdash.method}
\aliasA{viewMins,XIntegerViews-method}{Views-utils}{viewMins,XIntegerViews.Rdash.method}
\aliasA{viewRangeMaxs}{Views-utils}{viewRangeMaxs}
\aliasA{viewRangeMaxs,RleViews-method}{Views-utils}{viewRangeMaxs,RleViews.Rdash.method}
\aliasA{viewRangeMaxs,RleViewsList-method}{Views-utils}{viewRangeMaxs,RleViewsList.Rdash.method}
\aliasA{viewRangeMins}{Views-utils}{viewRangeMins}
\aliasA{viewRangeMins,RleViews-method}{Views-utils}{viewRangeMins,RleViews.Rdash.method}
\aliasA{viewRangeMins,RleViewsList-method}{Views-utils}{viewRangeMins,RleViewsList.Rdash.method}
\aliasA{viewSums}{Views-utils}{viewSums}
\aliasA{viewSums,RleViews-method}{Views-utils}{viewSums,RleViews.Rdash.method}
\aliasA{viewSums,RleViewsList-method}{Views-utils}{viewSums,RleViewsList.Rdash.method}
\aliasA{viewSums,XIntegerViews-method}{Views-utils}{viewSums,XIntegerViews.Rdash.method}
\aliasA{viewWhichMaxs}{Views-utils}{viewWhichMaxs}
\aliasA{viewWhichMaxs,RleViews-method}{Views-utils}{viewWhichMaxs,RleViews.Rdash.method}
\aliasA{viewWhichMaxs,RleViewsList-method}{Views-utils}{viewWhichMaxs,RleViewsList.Rdash.method}
\aliasA{viewWhichMaxs,XIntegerViews-method}{Views-utils}{viewWhichMaxs,XIntegerViews.Rdash.method}
\aliasA{viewWhichMins}{Views-utils}{viewWhichMins}
\aliasA{viewWhichMins,RleViews-method}{Views-utils}{viewWhichMins,RleViews.Rdash.method}
\aliasA{viewWhichMins,RleViewsList-method}{Views-utils}{viewWhichMins,RleViewsList.Rdash.method}
\aliasA{viewWhichMins,XIntegerViews-method}{Views-utils}{viewWhichMins,XIntegerViews.Rdash.method}
\keyword{methods}{Views-utils}
\keyword{algebra}{Views-utils}
\keyword{arith}{Views-utils}
\begin{Description}\relax
The \code{slice} function creates a \LinkA{Views}{Views.Rdash.class} object that contains
the indices where the data are within the specified bounds.

The \code{viewMins}, \code{viewMaxs}, \code{viewSums}, \code{viewMeans}
functions calculate the minima, maxima, sums, and means on views respectively.
\end{Description}
\begin{Usage}
\begin{verbatim}
  viewApply(X, FUN, ..., simplify = TRUE)

  slice(x, lower=-Inf, upper=Inf, ...)
  ## S4 method for signature 'Rle':
  slice(x, lower=-Inf, upper=Inf,
                        includeLower=TRUE, includeUpper=TRUE,
                        rangesOnly = FALSE)

  viewMins(x, na.rm=FALSE)
  viewMaxs(x, na.rm=FALSE)
  viewSums(x, na.rm=FALSE)
  viewMeans(x, na.rm=FALSE)

  viewWhichMins(x, na.rm=FALSE)
  viewWhichMaxs(x, na.rm=FALSE)

  viewRangeMins(x, na.rm=FALSE)
  viewRangeMaxs(x, na.rm=FALSE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{X}] A Views object.

\item[\code{FUN}] The function to be applied to each view in \code{X}.

\item[\code{...}] Additional arguments to be passed on.

\item[\code{simplify}] A logical value specifying whether or not the result should be simplified
to a vector or matrix if possible.

\item[\code{x}] An \LinkA{Rle}{Rle.Rdash.class}, \LinkA{RleList}{RleList.Rdash.class}, \LinkA{XInteger}{XInteger.Rdash.class} object
or an integer vector for \code{slice}.

An \LinkA{RleViews}{RleViews.Rdash.class}, \LinkA{RleViewsList}{RleViewsList.Rdash.class},
\LinkA{XIntegerViews}{XIntegerViews.Rdash.class} object for \code{viewMins}, \code{viewMaxs},
\code{viewSums}, and \code{viewMeans}.

An \LinkA{Rle}{Rle.Rdash.class}, \LinkA{RleViewsList}{RleViewsList.Rdash.class},
\LinkA{XIntegerViews}{XIntegerViews.Rdash.class} object for \code{viewWhichMins} and
\code{viewWhichMaxs}.

\item[\code{lower, upper}] The lower and upper bounds for the slice.

\item[\code{includeLower, includeUpper}] Logical indicating whether or not the specified boundary is open or closed.

\item[\code{rangesOnly}] For \LinkA{Rle}{Rle.Rdash.class} and \LinkA{RleList}{RleList.Rdash.class} objects, a logical
indicating whether or not to drop the original data from the output.

\item[\code{na.rm}] Logical indicating whether or not to include missing values in the results.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The \code{slice} function is useful for finding areas of absolute maxima
(peaks), absolute minima (troughs), or fluctuations within specified limits.

The \code{viewMins}, \code{viewMaxs}, \code{viewSums}, and \code{viewMeans}
functions provide efficient methods for calculating the specified numeric
summary by performing the looping in compiled code.

The \code{viewWhichMins}, \code{viewWhichMaxs}, \code{viewRangeMins}, and
\code{viewRangeMaxs} functions provide efficient methods for finding the
locations of the minima and maxima.
\end{Details}
\begin{Value}
An \LinkA{RleViews}{RleViews.Rdash.class} object for \LinkA{Rle}{Rle.Rdash.class} or an
\LinkA{RleViewsList}{RleViewsList.Rdash.class} for \LinkA{RleList}{RleList.Rdash.class} containing the
views when using \code{slice} with \code{rangesOnly = FALSE}.
An \LinkA{IRanges}{IRanges.Rdash.class} object for \LinkA{Rle}{Rle.Rdash.class} or a
\LinkA{CompressedIRangesList}{CompressedIRangesList.Rdash.class} for \LinkA{RleList}{RleList.Rdash.class} containing
the ranges when using \code{slice} with \code{rangesOnly = TRUE}.
An \LinkA{XIntegerViews}{XIntegerViews.Rdash.class} for an \LinkA{XInteger}{XInteger.Rdash.class} object
when using \code{slice}.

A vector of \code{length(x)} for \LinkA{RleViews}{RleViews.Rdash.class} and
\LinkA{XIntegerViews}{XIntegerViews.Rdash.class} objects or a \LinkA{SimpleList}{SimpleList.Rdash.class} object of
\code{length(x)} for \LinkA{RleViewsList}{RleViewsList.Rdash.class} objects containing the
numeric summaries for the views for \code{viewMins}, \code{viewMaxs},
\code{viewSums}, \code{viewMeans}, \code{viewWhichMins}, and
\code{viewWhichMaxs}.

An \LinkA{IRanges}{IRanges.Rdash.class} object for \LinkA{RleViews}{RleViews.Rdash.class} objects or a
\LinkA{SimpleIRangesList}{SimpleIRangesList.Rdash.class} for \LinkA{RleViewsList}{RleViewsList.Rdash.class} objects
containing the location ranges for \code{viewRangeMins} and
\code{viewRangeMaxs}.
\end{Value}
\begin{Author}\relax
P. Aboyoun
\end{Author}
\begin{SeeAlso}\relax
\LinkA{RleViews-class}{RleViews.Rdash.class}, \LinkA{RleViewsList-class}{RleViewsList.Rdash.class}, \LinkA{XIntegerViews-class}{XIntegerViews.Rdash.class},
\code{\LinkA{which.min}{which.min}}, \code{\LinkA{colSums}{colSums}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  ## Views derived from vector
  vec <- as.integer(c(19, 5, 0, 8, 5))
  slice(vec, lower=5, upper=8)

  set.seed(0)
  vec <- sample(24)
  vecViews <- slice(vec, lower=4, upper=16)
  vecViews
  viewApply(vecViews, function(x) diff(as.integer(x)))
  viewMins(vecViews)
  viewMaxs(vecViews)
  viewSums(vecViews)
  viewMeans(vecViews)
  viewWhichMins(vecViews)
  viewWhichMaxs(vecViews)

  ## Views derived from coverage
  x <- IRanges(start=c(1L, 9L, 4L, 1L, 5L, 10L),
               width=c(5L, 6L, 3L, 4L, 3L,  3L))
  slice(coverage(x), lower=2)
  slice(coverage(x), lower=2, rangesOnly = TRUE)
\end{ExampleCode}
\end{Examples}

