R/tb.R

Defines functions tb

#' wrapper for table() that sorts by counts, decreasing
#'
#' @param x required, passed to table(x)
#' @param useNA default is 'always', passed to table()
#' @param ... other parameters passed to table() -- cannot pass anything to cbind or sort like decreasing=FALSE
#'
#' @return like cbind
#' @export
#' 
tb <- function(x, useNA = 'always', ...) {
  result <- cbind(sort(table(x, useNA=useNA, ...), decreasing=TRUE)) 
  names(result) <- 'count'
  return(result)
  # ignores anything passed to sort or cbind, including decreasing=FALSE
}
ejanalysis/analyze.stuff documentation built on April 2, 2024, 10:10 a.m.