uniq | R Documentation |
The function uniq
returns a vector, list or data frame with duplicated elements
removed. By default, the function prints a data frame with missing values omitted
and unique elements 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, write = NULL, append = TRUE, check = TRUE, output = 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 |
write |
a character string naming a file for writing the output into
either a text file with file extension |
append |
logical: if |
check |
logical: if |
output |
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 an object of class misty.object
when using the uniq
function,
which is a list with following entries:
call |
function call |
type |
type of analysis |
data |
a vector, factor, matrix, or data frame |
args |
specification of function arguments |
result |
list with unique elements |
or a vector with the count number of unique elements for a vector, factor or
each column in a matrix or data frame when using the uniq.n
function.
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.