DeleteDuplicatesBy
DeleteDuplicatesBy[data,f]
deletes those ei in data that yield duplicates in the list {f[e1],f[e2],…}.
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 allBasic 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)
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]]:
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