Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rmdupkey

Remove observations with duplicate keys from data


Description

Takes in a data and key, and returns data with duplicate observations by key removed

Usage

rmdupkey(data, by)

Arguments

data

a data.frame or data.table

by

a character vector of keys to be used

Details

Remove duplicate observations by key(s) is what this function does. How it is different from other functions that remove duplicates is that rmdupkey works for both 'data.frame' and 'data.table', and it also returns the duplicated observations.

Many a times we want to go back to the duplicated observations and see why that duplication occured. One can pick the duplicated observations using the code given in example.

Value

a two element list: unique data and duplicate data

Author(s)

Akash Jain

See Also

Examples

# A 'data.frame'
df <- data.frame(x = c(1, 2, 1, 1), y = c(3, 3, 1, 3))

# Remove duplicate observations by key from data
ltDf <- rmdupkey(data = df, by = c('x'))
unqDf <- ltDf$unqData
dupDf <- ltDf$dupData

StatMeasures

Easy Data Manipulation, Data Quality and Statistical Checks

v1.0
GPL-2
Authors
Akash Jain
Initial release
2015-03-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.