Learn R Programming

shipunov (version 1.17.1)

Alldups: Finds all duplicates

Description

Finds duplicates from both ends, optionally returns indexes of duplicate groups

Usage

Alldups(v, groups=FALSE)

Value

Logical vector of length equal to 'v', or numerical vector if 'groups=TRUE'

Arguments

v

Vector, matrix or data frame

groups

If TRUE, returns group indexes (non-duplicated are 0)

Author

Alexey Shipunov

Details

This is extension of duplicated() which _does not_ skip the first duplicate in each group. 'NA' consider for duplicates but do not count as duplicate group.

If the first argument is a matrix or data frame and 'groups=TRUE', Aldups() starts from converting them into character vector with paste0(..., collapse="").

If 'groups=TRUE', Alldups() uses as.numeric(as.character(v)) twice to index duplicated groups with natural numbers (and non-duplicated with 0).

See Also

Examples

Run this code
aa <- c("one", "two", "", NA, "two", "three", "three", "three", NA, "", "four")
Alldups(aa)
data.frame(v=aa, dups=Alldups(aa), groups=Alldups(aa, groups=TRUE))

## clustering based on duplicates from rounding
(iris.dgr <- Alldups(round(iris[, 1:4]/10), groups=TRUE))
Misclass(iris.dgr, iris$Species, best=TRUE)

Run the code above in your browser using DataLab