R_ Determine Duplicate Elements

© All Rights Reserved

2 views

R_ Determine Duplicate Elements

© All Rights Reserved

- MatLab Plane Stress Example
- Exam_2_prep
- lk
- TDK Man DarkBasic Part1
- By Vijay Kumar
- y-bus1.docx
- 4_6 Multidimensional Arrays
- 2009 Labview Exercises
- 8
- Data Structures Questions Part 1 _ Amcatblog
- Bubble Sort
- Unit 5 - Object Oriented Programming / C++
- LAB 01 One-Dimensional Arrays
- Mat Lab Heat Conduction Example
- sw_lab
- Opencv User
- Computing Mock
- Notes on MATLAB Programming
- Trilinos10.6Tutorial
- user_import.txt

You are on page 1of 3

html

Description

duplicated() determines which elements of a vector or data frame are duplicates of elements

with smaller subscripts, and returns a logical vector indicating which elements (rows) are

duplicates.

Usage

## Default S3 method:

duplicated(x, incomparables = FALSE,

fromLast = FALSE, nmax = NA, ...)

duplicated(x, incomparables = FALSE, MARGIN = 1,

fromLast = FALSE, ...)

## Default S3 method:

anyDuplicated(x, incomparables = FALSE,

fromLast = FALSE, ...)

## S3 method for class 'array'

anyDuplicated(x, incomparables = FALSE,

MARGIN = 1, fromLast = FALSE, ...)

Arguments

x

a vector or a data frame or an array or NULL.

incomparables

a vector of values that cannot be compared. FALSE is a special value, meaning

that all values can be compared, and may be the only value accepted for methods

other than the default. It will be coerced internally to the same type as x.

fromLast

logical indicating if duplication should be considered from the reverse side, i.e.,

the last (or rightmost) of identical elements would correspond to duplicated =

FALSE.

nmax

the maximum number of unique items expected (greater than one).

...

arguments for particular methods.

1 of 3 08/Sep/2017, 7:34 PM

R: Determine Duplicate Elements http://127.0.0.1:16480/library/base/html/duplicated.html

MARGIN

the array margin to be held fixed: see apply, and note that MARGIN = 0 maybe

useful.

Details

These are generic functions with methods for vectors (including lists), data frames and arrays

(including matrices).

For the default methods, and whenever there are equivalent method definitions for duplicated

and anyDuplicated, anyDuplicated(x, ...) is a generalized shortcut for any(duplicated(x,

...)), in the sense that it returns the index i of the first duplicated entry x[i] if there is one, and 0

otherwise. Their behaviours may be different when at least one of duplicated and

anyDuplicated has a relevant method.

The data frame method works by pasting together a character representation of the rows separated

by \r, so may be imperfect if the data frame has characters with embedded carriage returns or

columns which do not reliably map to characters.

The array method calculates for each element of the sub-array specified by MARGIN if the

remaining dimensions are identical to those for an earlier (or later, when fromLast = TRUE)

element (in row-major order). This would most commonly be used to find duplicated rows (the

default) or columns (with MARGIN = 2). Note that MARGIN = 0 returns an array of the same

dimensionality attributes as x.

Missing values ("NA") are regarded as equal, numeric and complex ones differing from NaN;

character strings will be compared in a common encoding; for details, see match (and unique)

which use the same concept.

Values in incomparables will never be marked as duplicated. This is intended to be used for a

fairly small set of values and will not be efficient for a very large set.

When used on a data frame with more than one column, or an array or matrix when comparing

dimensions of length greater than one, this tests for identity of character representations. This will

catch people who unwisely rely on exact equality of floating-point numbers!

Except for factors, logical and raw vectors the default nmax = NA is equivalent to nmax =

length(x). Since a hash table of size 8*nmax bytes is allocated, setting nmax suitably can save

large amounts of memory. For factors it is automatically set to the smaller of length(x) and the

number of levels plus one (for NA). If nmax is set too small there is liable to be an error: nmax = 1

is silently ignored.

Long vectors are supported for the default method of duplicated, but may only be usable if nmax

is supplied.

Value

duplicated(): For a vector input, a logical vector of the same length as x. For a data frame, a

2 of 3 08/Sep/2017, 7:34 PM

R: Determine Duplicate Elements http://127.0.0.1:16480/library/base/html/duplicated.html

logical vector with one element for each row. For a matrix or array, and when MARGIN = 0, a

logical array with the same dimensions and dimnames.

anyDuplicated(): an integer or real vector of length one with value the 1-based index of the first

duplicate if any, otherwise 0.

Warning

Using this for lists is potentially slow, especially if the elements are not atomic vectors (see

vector) or differ only in their attributes. In the worst case it is O(n^2).

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth &

Brooks/Cole.

See Also

unique.

Examples

## extract unique elements

(xu <- x[!duplicated(x)])

## similar, same elements but different order:

(xu2 <- x[!duplicated(x, fromLast = TRUE)])

stopifnot(identical(xu, unique(x)),

identical(xu2, unique(x, fromLast = TRUE)))

duplicated(iris)[140:143]

anyDuplicated(iris) ## 143

anyDuplicated(x)

anyDuplicated(x, fromLast = TRUE)

3 of 3 08/Sep/2017, 7:34 PM

- MatLab Plane Stress ExampleUploaded byChristine Mamagkinidou
- Exam_2_prepUploaded byAhmad Radzi
- lkUploaded by53melmel
- TDK Man DarkBasic Part1Uploaded byAweryn
- By Vijay KumarUploaded bykumud_kedia
- y-bus1.docxUploaded byAkshay Gattu
- 4_6 Multidimensional ArraysUploaded byAdarsh Korath
- 2009 Labview ExercisesUploaded byViktor_Ramirez_2115
- 8Uploaded bythien
- Data Structures Questions Part 1 _ AmcatblogUploaded byVishnu Kumar
- Bubble SortUploaded byrajalakshmiammu
- Unit 5 - Object Oriented Programming / C++Uploaded bySyafiq Fauzi
- LAB 01 One-Dimensional ArraysUploaded byNina Ricci
- Mat Lab Heat Conduction ExampleUploaded byKelvin L
- sw_labUploaded bySreekant Somasekharan
- Opencv UserUploaded byapoks88
- Computing MockUploaded bymatthew_cox_2
- Notes on MATLAB ProgrammingUploaded byvisakoushik
- Trilinos10.6TutorialUploaded byRazibul Islam
- user_import.txtUploaded byliftfund
- The Computer Science HandbookUploaded byAmine Badraoui
- Excel FAQUploaded byPallab Datta
- MatLabSlides.pdfUploaded byDanilo Pequeno
- Final List of ExperimentsUploaded byabcd
- relasi 2g-3gUploaded byreza
- XII_Computer_Science_SQP_2018_19.pdfUploaded byprabhu prasad pradhan
- Arrays FunctionUploaded byishini
- Array and EnumUploaded byNithin Ricky
- 1Uploaded byVskm Nagarajan Muthuragavan
- 08 Slide trUploaded byBimbimay Salvacion

- R cheatsheet Data WranglingUploaded byarekbee
- Lunar 2018Uploaded byloshude
- R_ Character Translation and CasefoldingUploaded byloshude
- R_ Report Capabilities of This Build of RUploaded byloshude
- Datatable Cheat Sheet RUploaded byloshude
- R_ Numeric VersionsUploaded byloshude
- R_ Push Text Back on to a ConnectionUploaded byloshude
- R_ Class for 'No Quote' Printing of Character StringsUploaded byloshude
- R_ Time Intervals _ DifferencesUploaded byloshude
- R_ Date ClassUploaded byloshude
- R_ Combine Values Into a Vector or ListUploaded byloshude
- R_ Functions to Retrieve Values Supplied by Calls to the BrowserUploaded byloshude
- R_ Functions to Manipulate Connections (Files, URLs, ...)Uploaded byloshude
- R_ Apply a Function to a Data Frame Split by FactorsUploaded byloshude
- R_ Bitwise Logical OperationsUploaded byloshude
- R_ Binding and Environment Locking, Active BindingsUploaded byloshude
- R_ Environment AccessUploaded byloshude
- R_ QuotesUploaded byloshude
- R_ the QR Decomposition of a MatrixUploaded byloshude
- R_ Display Numbers in OctalUploaded byloshude
- R_ Approximate String Matching (Fuzzy Matching)Uploaded byloshude
- R_ Lists - Generic and Dotted PairsUploaded byloshude
- R_ Date-Time ClassesUploaded byloshude
- R_ FactorsUploaded byloshude
- Approximate String Distances in RUploaded byloshude
- Data Output in rUploaded byloshude
- Dplyr Windows Rank in rUploaded byloshude
- Dplyr Helpers in rUploaded byloshude
- dphly lead lag in rUploaded byloshude

- Understanding Sap.ui.Table.table in 10 MinutesUploaded byJulio Rafael
- programming with c++ 1Uploaded byapi-282924820
- OOP with C++ LabUploaded byVikram Rao
- s71200 System Manual en-US en-USUploaded byandrea772
- Algorithms (OBF) Dummies_SPARKUploaded byrs4895
- Multi Dim Point DataUploaded byFelix Oghină
- Data HandlingUploaded bySyed Abdul Haseeb Ahmed
- 5_6258291087174008840.pdfUploaded bysalim
- tut1Uploaded byChandan Kr
- Comunicacion Plc y Pac3200Uploaded bySamir Conrado Iguaran
- Javolution-CollectionsUploaded bydknitk
- Matrix ProgrammingUploaded byŠjor Polović
- 4 Hive Tutorial d03Uploaded byGyan Sharma
- The Use of Prime Generators to Implement Fast Twin Primes Sieve Of Zakiya(SoZ), Applications to Number Theory, and Implications for the Riemann HypothesesUploaded byJabari Zakiya
- Tools for Structured and Object Oriented Design - ArraysUploaded byAndrew Carts
- Extention of Unit 4Uploaded byMehaboob Basha
- PDF.pdfUploaded byFelix Stephen
- Make a Match-3 Game in Construct 2_ Animations and Block SwappingUploaded byVinicius de Almeida
- CompuStat Technical Guide (Tape, 2000)Uploaded bycarmo-neto
- iNTERVIEW qUESTIONC IN cUploaded bysagar_sea
- Graph AnalyticsUploaded bymbala86
- Introduction to Data Structures and AlgorithmsUploaded byVikas Sharma
- CBSE 2014 Question Paper for Class 12 Computer Science - Outside DelhiUploaded byaglasem
- ParaView User's Guide v3.10.pdfUploaded byAntônio Boness
- 930XII - Arrays Old Q&AUploaded byhuyeb
- ECTE333 Lecture 07Uploaded bySirish Sabbella
- Practical AI in JavaUploaded byNguyễn Viết Việt
- SystemVerilogForVerification_woQuizUploaded byKrishna Kishore
- Practical List XiiUploaded byChandresh Sharma
- When to Use Parallel for Each or Plin qUploaded byCristina Carstea

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.