% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/repeated.r
\name{repeated}
\alias{repeated}
\alias{repeated.array}
\alias{whichRepeated}
\alias{whichRepeated.array}
\alias{repeats}
\alias{repeats.array}
\alias{non.unique}
\title{Determine Repeated Elements}
\usage{
repeated(x, ...)

\method{repeated}{array}(x, MARGIN = 1L, ...)

whichRepeated(x, ...)

\method{whichRepeated}{array}(x, MARGIN = 1L, ...)

repeats(x, ...)

\method{repeats}{array}(x, MARGIN = 1L, ...)

non.unique(x, ...)
}
\arguments{
\item{x}{a vector, a data frame, an array, or \code{NULL}.}

\item{...}{additional arguments passed to methods.}

\item{MARGIN}{the array margin to be held fixed: see \link{apply},
and note that \code{MARGIN = 0} may be useful.}
}
\value{
\code{repeated()}: For a vector input, a logical vector of the
same length as \code{x}. For a data frame, a logical vector
with one element for each row. For a matrix or array, and
when \code{MARGIN = 0}, a logical array with the same dimensions
and dimnames.

\code{whichRepeated()}: For a vector input, an integer vector
giving the indices of the repeated values. For a data frame,
an integer vector giving the indices of the repeated rows.
For a matrix or array, an integer vector giving the indices
of the repeated elements across the margin specified.

\code{repeats()} and its alias \code{non.unique()}: an object of
the same type as \code{x}, containing the repeated values
(vector input), rows (data frame input), or elements across
the margin (matrix/array input).
}
\description{
Return a logical vector, indices, or the values of repeated elements
in a vector.
}
\details{
The \code{repeated} functions determine which elements of a vector
or data frame are duplicates of elements with smaller subscripts.
They are very similar in functionality to \link{duplicated} but
instead mark \strong{all} duplicates (not just those after the
first/last occurrence), and do not have an \code{incomparables}
argument.

These are generic functions with methods for vectors
(including lists and expressions), data frames and arrays
(including matrices).

The array method calculates for each element of the sub-array
specified by \code{MARGIN} if the dimensions are identical
to those for an earlier or later element (in row-major order).
This would most commonly be used to find repeated rows
(the default) or columns (with \code{MARGIN = 2}). Note that
\code{MARGIN = 0} returns an array of the same dimensionality
attributes as \code{x}.

\code{non.unique()} is an alias for \code{repeats()}.
}
\examples{
# Repeated values in a vector
x <- c(1, 2, 3, 2, 1)

repeated(x)
whichRepeated(x)
repeats(x)

# Repeated rows in a data frame
df <- data.frame(
  x = c(1, 2, 1),
  y = c("a", "b", "a")
)

repeated(df)
repeats(df)

# Repeated rows/columns in a matrix
m <- cbind(
  c(1, 2),
  c(3, 4),
  c(1, 2)
)

repeated(m)
repeated(m, MARGIN = 2)
repeats(m, MARGIN = 2)

# non.unique() is an alias for repeats()
identical(repeats(x), non.unique(x))
}
\seealso{
\link{duplicated} and \link{unique}.
}
