Find Duplicate Elements - Maple Help

DataSeries/AreDuplicate

determine duplicate elements in a DataSeries

 Calling Sequence AreDuplicate( data )

Parameters

 data -

Description

 • The AreDuplicate command returns a DataSeries of type truefalseFAIL where the elements correspond to true if the given element has duplicates in the DataSeries and false if the element is unique.
 • The output from the AreDuplicate command can be used to index a DataSeries or DataFrame in order to return the duplicate elements in a given column.

Examples

 > $\mathrm{DS}≔\mathrm{DataSeries}\left(⟨1,2,3,3,4,5,5,5⟩\right)$
 ${\mathrm{DS}}{≔}\left[\begin{array}{cc}{1}& {1}\\ {2}& {2}\\ {3}& {3}\\ {4}& {3}\\ {5}& {4}\\ {6}& {5}\\ {7}& {5}\\ {8}& {5}\end{array}\right]$ (1)

The AreDuplicate command returns a truefalseFAIL DataSeries that shows any duplicate values as true.

 > $\mathrm{AreDuplicate}\left(\mathrm{DS}\right)$
 $\left[\begin{array}{cc}{1}& {\mathrm{false}}\\ {2}& {\mathrm{false}}\\ {3}& {\mathrm{true}}\\ {4}& {\mathrm{true}}\\ {5}& {\mathrm{false}}\\ {6}& {\mathrm{true}}\\ {7}& {\mathrm{true}}\\ {8}& {\mathrm{true}}\end{array}\right]$ (2)

If the DataSeries is indexed by the result, a filtered DataSeries is returned that shows just the duplicate values:

 > $\mathrm{DS}\left[\mathrm{AreDuplicate}\left(\mathrm{DS}\right)\right]$
 $\left[\begin{array}{cc}{3}& {3}\\ {4}& {3}\\ {6}& {5}\\ {7}& {5}\\ {8}& {5}\end{array}\right]$ (3)

If a DataFrame is indexed by the result, a filtered DataFrame is returned that shows only the rows with duplicates in a given column.

 > $\mathrm{DF}≔\mathrm{DataFrame}\left(⟨⟨1,1,2,3,3,4⟩|⟨5,3,6,2,1,4⟩|⟨6,5,1,4,9,9⟩|⟨4,2,1,7,8,3⟩⟩\right)$
 ${\mathrm{DF}}{≔}\left[\begin{array}{ccccc}{}& {1}& {2}& {3}& {4}\\ {1}& {1}& {5}& {6}& {4}\\ {2}& {1}& {3}& {5}& {2}\\ {3}& {2}& {6}& {1}& {1}\\ {4}& {3}& {2}& {4}& {7}\\ {5}& {3}& {1}& {9}& {8}\\ {6}& {4}& {4}& {9}& {3}\end{array}\right]$ (4)

For example, the following shows just the rows with duplicate elements in the first column:

 > $\mathrm{DF}\left[\mathrm{AreDuplicate}\left(\mathrm{DF}\left[1\right]\right)\right]$
 $\left[\begin{array}{ccccc}{}& {1}& {2}& {3}& {4}\\ {1}& {1}& {5}& {6}& {4}\\ {2}& {1}& {3}& {5}& {2}\\ {4}& {3}& {2}& {4}& {7}\\ {5}& {3}& {1}& {9}& {8}\end{array}\right]$ (5)

This can also be combined with other queries in order to show rows that meet a given criteria. For example, to see which rows have duplicate elements in the first column and are greater than 2:

 > DF[ AreDuplicate( DF[1] ) and DF[1] >~ 2 ];
 $\left[\begin{array}{ccccc}{}& {1}& {2}& {3}& {4}\\ {4}& {3}& {2}& {4}& {7}\\ {5}& {3}& {1}& {9}& {8}\end{array}\right]$ (6)

Compatibility

 • The DataSeries/AreDuplicate command was introduced in Maple 2016.