# 3.5.8.21 Unique

## Description

This function takes a vector vs and returns the unique values. You can decide whether to sort the unique output values and how to reduce the duplicated values.

## Syntax

 Dataset or StringArray  Unique(vector<string> vs[, int Sort, int Occurrence, int sort2])

## Parameters

vs

is the vector in which unique values are searched

Sort

[optional] integer that specifies whether to sort the output unique values:
• sort = 1 (default), the output values are sorted in ascending order.
• sort = 0, the values are outputted without sorting.
• sort = 2, the output values are sorted in descending order.

Occurrence

[optional] integer that specifies how to reduce the duplicated values.
• occurrence = 0 (default), the first duplicated value is remained.
• occurrence = 1, the last duplicated value is remained.

sort2

[optional] occurrence sort:
• sort2 = 0 (default), no occurrence sort.
• sort2 = 1, occurrence ascending.
• sort2 = 2, occurrence descending.

## Return

Returns a vector of the unique values in vs.

## Examples

newbook;
col(A) = {1,10,15,8,2};
col(B) = unique(col(A));
StringArray sa;
sa = unique(col(a)); // assign unique values in col(a) to stringArray sa, sort in ascending order
range bb=col(b);
sa.CopyTo(bb); // copy contents of stringArray sa to col(b)
newbook;
wks.ncols = 3;
col(A) = {3, 1, 2, 3, 4, 1, 3, 4};
csetvalue col:=col(B) formula:="Unique(A,0,0,2)";
csetvalue col:=col(C) formula:="Unique(A,0,1,2)";