Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 6 additions & 5 deletions R/typical.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion man/typical.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.