R/su.R

Defines functions su

Documented in su

#' su: Sorted unique values
#'
#' Extract unique elements and sort them
#'
#' @param x a vector or a data frame or an array or NULL.
#' @param na.last an argument to be passed onto the 'sort' function
#' (in base R) for controlling the treatment of NA values.
#' If \code{na.last = TRUE}, NA values in the data are put last;
#' if \code{na.last = FALSE}, NA values are put first;
#' if \code{na.last = NA}, NA values are removed.
#' By default, \code{na.last = TRUE}
#' @param decreasing logical. Should the sort be increasing or decreasing?
#' An argument to be passed onto the 'sort' function (in base R).
#' By default, \code{decreasing = FALSE}
#' @return a vector, data frame, or array-like 'x' but with duplicate
#' elements/rows removed.
#' @examples
#' su(c(10, 3, 7, 10, NA))
#' su(c("b", "z", "b", "a", NA, NA, NA))
#' @export
su <- function(
  x = NULL,
  na.last = TRUE,
  decreasing = FALSE) {
  return(sort(unique(x), na.last = na.last, decreasing = decreasing))
}

Try the kim package in your browser

Any scripts or data that you put into this service are public.

kim documentation built on Oct. 9, 2023, 5:08 p.m.