Find Unique Elements - Maple Help

DataSeries/AreUnique

determine unique elements in a DataSeries

 Calling Sequence AreUnique( data )

Parameters

 data - options - options : (optional) equation(s) of the form option=value where option can be any of keep.

Options

 • keep : first, last, none; if a duplicate element is encountered, keep specifies which duplicate to retain

Description

 • The AreUnique command returns a DataSeries of type truefalseFAIL where the elements correspond to true if the given element is unique and false if the given element is a duplicate of another value in the given DataSeries.
 • The output from the AreUnique command can be used to index a DataSeries or DataFrame in order to return the unique rows in a given column.
 • The keep option allows for specification of which duplicate element value in the DataSeries to keep. By default, keep marks the first instance of a value that it encounters as unique (true) and marks any duplicates of this first instance as a duplicate (false). If keep is set to last, the last detected duplicate value is marked as unique (true) and any other matching values are marked as duplicate (false). If keep is set to none, any elements that have duplicates are marked as duplicates (false).

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 AreUnique command returns a truefalseFAIL DataSeries that shows all unique values as true.

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

If the DataSeries is indexed by the result, a filtered DataSeries is returned that removes any duplicate values:

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

The results can be used to index a DataFrame and remove the rows that have duplicate values in a specific 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)
 > $\mathrm{AreUnique}\left(\mathrm{DF}\left[1\right]\right)$
 $\left[\begin{array}{cc}{1}& {\mathrm{true}}\\ {2}& {\mathrm{false}}\\ {3}& {\mathrm{true}}\\ {4}& {\mathrm{true}}\\ {5}& {\mathrm{false}}\\ {6}& {\mathrm{true}}\end{array}\right]$ (5)

The keep option allows for specification of which row to keep, either the first, last or none, when a duplicate is found:

 > $\mathrm{DF}\left[\mathrm{AreUnique}\left(\mathrm{DF}\left[1\right],\mathrm{keep}=\mathrm{first}\right)\right]$
 $\left[\begin{array}{ccccc}{}& {1}& {2}& {3}& {4}\\ {1}& {1}& {5}& {6}& {4}\\ {3}& {2}& {6}& {1}& {1}\\ {4}& {3}& {2}& {4}& {7}\\ {6}& {4}& {4}& {9}& {3}\end{array}\right]$ (6)
 > $\mathrm{DF}\left[\mathrm{AreUnique}\left(\mathrm{DF}\left[1\right],\mathrm{keep}=\mathrm{last}\right)\right]$
 $\left[\begin{array}{ccccc}{}& {1}& {2}& {3}& {4}\\ {2}& {1}& {3}& {5}& {2}\\ {3}& {2}& {6}& {1}& {1}\\ {5}& {3}& {1}& {9}& {8}\\ {6}& {4}& {4}& {9}& {3}\end{array}\right]$ (7)

If keep is set to none, all rows that have a duplicate value in a column are marked as false.

 > $\mathrm{DF}\left[\mathrm{AreUnique}\left(\mathrm{DF}\left[1\right],\mathrm{keep}=\mathrm{none}\right)\right]$
 $\left[\begin{array}{ccccc}{}& {1}& {2}& {3}& {4}\\ {3}& {2}& {6}& {1}& {1}\\ {6}& {4}& {4}& {9}& {3}\end{array}\right]$ (8)

Compatibility

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