DeleteDuplicatesBy

DeleteDuplicatesBy[data,f]

deletes those ei in data that yield duplicates in the list {f[e1],f[e2],}.

DeleteDuplicatesBy[f]

represents an operator form of DeleteDuplicatesBy that can be applied to an expression.

Details

  • DeleteDuplicatesBy[data,f] deletes all but the first ei in the first level of the input data to produce each distinct value of f[ei].
  • The data can have the following forms:
  • {e1,e2,}list of values, including numbers, quantities, dates, ...
    Association[]association of values
    QuantityArray[]quantity array or other structured array
    Tabular[]type-consistent tabular data
    TabularColumn[]type-consistent column data
    Dataset[]general hierarchical data
  • DeleteDuplicatesBy[<|key1val1,key2val2,|>,f] deletes values of f[vali] that duplicate earlier elements, ignoring the keyi.
  • For a Tabular object tab, DeleteDuplicatesBy[tab,f] applies the function f to individual rows of tab, with the row being an association <|col1val1,|> if tab has column keys or a list {val1,} if tab does not have column keys.
  • DeleteDuplicatesBy never reorders elements, but only removes them.
  • DeleteDuplicatesBy[f][expr] is equivalent to DeleteDuplicatesBy[expr,f].

Examples

open allclose all

Basic Examples  (2)

Delete pairs with a duplicate last element:

Delete values from an association that have the same magnitude:

Use the operator form of DeleteDuplicatesBy:

Scope  (4)

The data need not have head List:

Remove duplicate rows in a Tabular object:

Use the string name when comparing the values in the column directly:

Delete duplicate rows by comparing the values of a function applied to a given column:

Delete duplicate rows in a Dataset object:

Properties & Relations  (3)

DeleteDuplicatesBy[list,Identity] is equivalent to DeleteDuplicates[list]:

DeleteDuplicatesBy[list,f] transforms each element using f, then compares the results:

DeleteDuplicates[list,test] applies test to two elements to determine if they are duplicates:

CountDistinctBy[list] is equivalent to Length[DeleteDuplicatesBy[list]]:

Wolfram Research (2014), DeleteDuplicatesBy, Wolfram Language function, https://reference.wolfram.com/language/ref/DeleteDuplicatesBy.html (updated 2025).

Text

Wolfram Research (2014), DeleteDuplicatesBy, Wolfram Language function, https://reference.wolfram.com/language/ref/DeleteDuplicatesBy.html (updated 2025).

CMS

Wolfram Language. 2014. "DeleteDuplicatesBy." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/DeleteDuplicatesBy.html.

APA

Wolfram Language. (2014). DeleteDuplicatesBy. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DeleteDuplicatesBy.html

BibTeX

@misc{reference.wolfram_2024_deleteduplicatesby, author="Wolfram Research", title="{DeleteDuplicatesBy}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/DeleteDuplicatesBy.html}", note=[Accessed: 17-January-2025 ]}

BibLaTeX

@online{reference.wolfram_2024_deleteduplicatesby, organization={Wolfram Research}, title={DeleteDuplicatesBy}, year={2025}, url={https://reference.wolfram.com/language/ref/DeleteDuplicatesBy.html}, note=[Accessed: 17-January-2025 ]}