R/duplicate_rows.R

Defines functions duplicated_rows

Documented in duplicated_rows

#' Function to return duplicated rows in a data frame. 
#' 
#' \code{duplicated_rows} can be though as the inverse of \code{\link{distinct}}. 
#' 
#' @param df Data frame. 
#' 
#' @param variable A vector of variables to test for uniqueness.
#' 
#' @param invert Should the function exclude duplicated. This is the same as
#' \code{\link{distinct}}. 
#' 
#' @return Data frame. 
#' 
#' @author Stuart K. Grange
#' 
#' @export
duplicated_rows <- function(df, variable, invert = FALSE) {
  
  if (invert) {
    
    df <- df[!duplicated(df[, variable]), ]
    
  } else {
    
    df <- df[duplicated(df[, variable]), ]
    
  }
  
  return(df)
  
}
skgrange/threadr documentation built on May 11, 2024, 12:16 p.m.