uniq | R Documentation |
The function uniq
returns a vector or data frame with duplicated elements
removed. By default, missing values are omitted and unique elements are sorted
increasing. The function uniq.n
counts the number of unique elements
in a vector or for each column in a matrix or data frame. By default, missing
values are omitted before counting the number of unique elements.
uniq(data, ..., na.rm = TRUE, sort = TRUE, decreasing = FALSE, digits = NULL,
table = TRUE, check = TRUE )
uniq.n(data, ..., na.rm = TRUE, digits = NULL, check = TRUE)
data |
a vector, factor, matrix, or data frame. |
... |
an expression indicating the variable names in |
na.rm |
logical: if |
sort |
logical: if |
decreasing |
logical: if |
digits |
an integer value indicating the number of decimal places to
be used when rounding numeric values before extracting unique
elements. By default, unique elements are extracted without
rounding, i.e., |
table |
logical: if |
check |
logical: if |
The function uniq
is a wrapper function in the form of sort(unique(na.omit(x)))
,
while the function uniq.n
is a wrapper function in the form of length(unique(na.omit(x)))
.
Returns a vector, factor, data frame, or list.
Takuya Yanagida
Becker, R. A., Chambers, J. M., & Wilks, A. R. (1988). The New S Language. Wadsworth & Brooks/Cole.
df.duplicated
, df.unique
#----------------------------------------------------------------------------
# Extract Unique Elements, uniq() function
# Example 1a: Extract unique elements in a vector
uniq(airquality, Ozone)
# Example 1b: Extract unique elements in a vector, round elements
uniq(airquality, Wind, digits = 0)
# Example 1b: Extract unique elements in a vector, do not sort
uniq(airquality, Ozone, sort = FALSE)
# Example 1b: Extract unique elements in a vector, keep NA
uniq(airquality, Ozone, na.rm = FALSE)
# Example 2a: Extract unique elements in a data frame
uniq(airquality)
# Example 2a: Extract unique elements in list
uniq(airquality, table = FALSE)
#----------------------------------------------------------------------------
# Count Number of Unique Elements, uniq.n() function
# Example 3a: Count number of unique elements in a vector
uniq.n(airquality, Ozone)
# Example 1b: Count number of unique elements for each variable in a data frame
uniq.n(airquality)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.