get_duplicated_rows: Extract observations (rows) that have same values in a tibble

get_duplicated_rowsR Documentation

Extract observations (rows) that have same values in a tibble

Description

This helper function extracts the row number (or first column value) in a tibble having identical values for all columns. This function can be used either on the whole columns or excluding the first column (id) (which can be useful to identify repeated observation across different ids)

Usage

get_duplicated_rows(tbl, id_col = NULL)

Arguments

tbl

R object(dataframe or tibble) of the input tibble

id_col

A character string specifying the column to ignore in identification of repeated observations. If NULL (by default), all of the columns will be taken in account for repeated observation identification. The row number will be used to identify those observations.

Value

A tibble indicating which row which values is the same in the tibble

Examples

{

# the row numbers are returned to identify which observations have repeated
# values
library(dplyr)
get_duplicated_rows(tbl = bind_rows( tbl = mtcars, mtcars[1,]))

get_duplicated_rows(
  tbl = bind_rows(mtcars,mtcars[1,]) %>%
        add_index() %>%
        mutate(index = paste0('obs_',index)),
  id_col = 'index')

}


fabR documentation built on May 29, 2024, 2:58 a.m.