Member-only story
How to Use the Unique() Function in R Programming
Have a lot of values in the dataset? Use unique to identify the unique observations.
While conducting exploratory data analysis analysts have a number of functions to help describe their datasets. In R programming the data usually is in a vector format (vector, matrix, data frame, etc.). So analysts turn to functions that can describe the data while in that vectorization format. One little-known function is the unique() function.
The unique() function is capable of revealing which values are in the data when the value is duplicated repeatedly in the dataset.
The syntax for unique() is:
unique(x)
where x is a vector. So for an example of what is returned, let’s take the gtcars dataset in the gt library and assign it to an object called cars. The syntax will look like the following:
cars <- gt :: gtcars
When you type cars, R will return a few of the columns and rows for display purposes.