diff --git a/NEWS.md b/NEWS.md index 723bc45..368d74c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # modelr 0.1.1.9000 +* Added `...` argument to the `typical()` generic function (@jrnold, #42) + * Added `typical.ordered` and `typical.integer` methods (@jrnold, #44) # modelr 0.1.1 diff --git a/R/typical.R b/R/typical.R index 95e1f32..64f6d51 100644 --- a/R/typical.R +++ b/R/typical.R @@ -6,6 +6,7 @@ #' them all. \code{NA} missing values are always silently dropped. #' #' @param x A vector +#' @param ... Arguments used by methods #' @export #' @importFrom stats quantile #' @examples @@ -24,29 +25,29 @@ #' # median of an ordered factor #' typical(ordered(c("a", "a", "b", "c", "d"))) #' -typical <- function(x) { +typical <- function(x, ...) { UseMethod("typical") } #' @export -typical.numeric <- function(x) { +typical.numeric <- function(x, ...) { stats::median(x, na.rm = TRUE) } #' @export -typical.factor <- function(x) { +typical.factor <- function(x, ...) { counts <- table(x) levels(x)[max(counts) == counts] } #' @export -typical.character <- function(x) { +typical.character <- function(x, ...) { counts <- table(x) names(counts)[max(counts) == counts] } #' @export -typical.logical <- function(x) { +typical.logical <- function(x, ...) { mean(x, na.rm = TRUE) >= 0.5 } diff --git a/man/typical.Rd b/man/typical.Rd index 05ec699..31a71a7 100644 --- a/man/typical.Rd +++ b/man/typical.Rd @@ -4,10 +4,12 @@ \alias{typical} \title{Find the typical value} \usage{ -typical(x) +typical(x, ...) } \arguments{ \item{x}{A vector} + +\item{...}{Arguments used by methods} } \description{ For numeric, integer, and ordered factor vectors, it returns the median.