2 views

Uploaded by loshude

R_ Determine Duplicate Elements

- Data Structures
- GuiaR
- 1521Instructions.pdf
- MatlabOutline.pdf
- computation calculator
- Chapter 8 - Two Dimensional Arrays
- 014BSCIT029_JAVA_1.docx
- Matlab Basics
- Lab1
- Matlab Intro
- moje_objasnjenje_koda
- Matlab Basics
- Guia de Algunos Comandos Útiles en Matlab
- Lecture2013.03.05
- Arrays of Arrays - Csharp
- Scientific Programming in Python
- Lecture 4 S16
- Scilab Basics
- chap 12.pdf
- 9781783555253_Mastering_Scientific_Computing_with_R_Sample_Chapter

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

- Data StructuresUploaded bysivaprasadadiraju
- GuiaRUploaded byAnabel Almeida
- 1521Instructions.pdfUploaded byAdauto Alves
- MatlabOutline.pdfUploaded bytkortiz24
- computation calculatorUploaded byMofoleni Bolabi Coloni II
- Chapter 8 - Two Dimensional ArraysUploaded byAhmadali
- 014BSCIT029_JAVA_1.docxUploaded byBwapii Thex
- Matlab BasicsUploaded byTewodros
- Lab1Uploaded byAnsari Rehan
- Matlab IntroUploaded byRene Zamora
- moje_objasnjenje_kodaUploaded byBarakataxs Crazzy's
- Matlab BasicsUploaded bysuresh270
- Guia de Algunos Comandos Útiles en MatlabUploaded byAdrian Delgado Jaime
- Lecture2013.03.05Uploaded bypikachu_latias_latios
- Arrays of Arrays - CsharpUploaded byManoj Kavedia
- Scientific Programming in PythonUploaded bystreetcribdealer
- Lecture 4 S16Uploaded bypascal joe
- Scilab BasicsUploaded by'babi Mulugeta
- chap 12.pdfUploaded byInblood
- 9781783555253_Mastering_Scientific_Computing_with_R_Sample_ChapterUploaded byPackt Publishing
- UI Components.pptUploaded byBasava Prabhu
- Chapter No 4Uploaded byZeeshan Faiz
- NI Tutorial 7571 EnUploaded byjayris2060049
- R Programming TutorialUploaded byKabira Kabira
- Matlab BasicsUploaded byDeepak Prakash Jaya
- Arrays and ClustersUploaded byghan
- computer_science_class_xi_structured_data_type.pdfUploaded byjagadish
- Arrays y Clusters in LabviewUploaded byeeindustrial
- singeisfnesoidfnesfneosfUploaded bybaseball604
- An Introduction to MATLAB for GeoscientistsUploaded bySergio Pablo Rodríguez

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

- EEG Electrical Surveying IPUploaded byErwin Anshari
- Spur Gear DesignUploaded bymshebbal2212
- TM-U230 Service Manual RevCUploaded byAnonymous y3SjtKG5w
- EMBEDDED SYSTEMS DESIGN USING ARM TECHNOLOGY.docxUploaded byAditya Shakya
- Natural_Farming_Fukuoka_Panos_Manikis_ideassonline.pdfUploaded bySujithShivu
- Method Statement of Soil InvestigationUploaded bybprimus
- ESMOD Dubai Rings in a Fashionable New YearUploaded byPR.com
- 24option.com eBookUploaded byrogue14
- unknowUploaded byAnonymous 1Xx4mQcqeT
- Rite Aid ProfileUploaded byjack
- Ocular Drug Delivery Systems_ Barriers -And- Application- Of- Nanoparticulate -Systems Deepak Thassu_ Gerald J. ChaderUploaded byAshwini Deshpande
- HCl Spec1Uploaded bycryovikas1975
- Stivers Modified Repeats EpistemicsUploaded byidschun
- 201412 Redmond MagazineUploaded bysivapvv
- Genotoxic Effects of Azo Dye AR-88 and Its Microbial Degraded Products on Fry of Cyprinus CarpioUploaded byESSENCE - International Journal for Environmental Rehabilitation and Conservaion
- EJERCICIOS 1º y Solucionario English PlusUploaded byCarlos Ruza Alejandre
- Introduction to Social Capital MarketUploaded bymir356563
- Mar final.docxUploaded byHồ Ly
- Al-Akel and SulimanUploaded byRio Pamungkas
- NWN SoU OnlineManualUploaded byJas
- Sap on Xiv AdvancedUploaded byfelipe_s_c
- Order in the matter of Jeevan Suraksha Real Estate LimitedUploaded byShyam Sunder
- TR - Cable TV Installation NC II.docUploaded byKaren Cañizares
- Nagaland Sales Tax Act 1967Uploaded byLatest Laws Team
- DotNet FrameWorkUploaded bybhargav_ram
- USB-4751Uploaded byrodson_c
- M40JDataSheetUploaded byVishaal Dhamotharan
- Definition for Business 1Uploaded byunintituc
- %2For...hich_EE_Ruchi%20Choudhary.pdfUploaded byAnurag Prabhakar
- 179Uploaded byAlfredoKytou