dupRowInds: Repeated indices of the first unique value

View source: R/helpers.R

dupRowIndsR Documentation

Repeated indices of the first unique value

Description

Repeated indices of the first unique value

Usage

dupRowInds(m)

Arguments

m

A matrix or a data frame.

This function is an inverse function to such operations as m[c(1:3, 1, 1, 2), ]: the matrix with potentially duplicated rows is taken as input, and repeated indices of the first occurrence of each row are returned.

This function is faster – at least in the examples tested so far – than match(data.frame(t(m)), data.frame(t(unique(m)))).

Value

A vector of row indices corresponding to the first ocurrence of a given row.

Examples

dupRowInds(mtcars[rep(1:10, 10), rep(1:10, 10)])
dupRowInds(matrix(rnorm(1000), ncol = 10))

pnd documentation built on Sept. 9, 2025, 5:44 p.m.