Learn R Programming

fabR (version 2.1.0)

get_duplicated_rows: 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)

Value

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

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.

Examples

Run this code
{

# 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')

}

Run the code above in your browser using DataLab