Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

mean_or_mode

Class-dependent variable aggregation


Description

Summarize a vector/variable into a single number, either a mean (median) for numeric vectors or the mode for categorical (character, factor, ordered, or logical) vectors. Useful for aggregation.

Usage

mean_or_mode(x)

## Default S3 method:
mean_or_mode(x)

## S3 method for class 'numeric'
mean_or_mode(x)

## S3 method for class 'data.frame'
mean_or_mode(x)

median_or_mode(x)

## Default S3 method:
median_or_mode(x)

## S3 method for class 'numeric'
median_or_mode(x)

## S3 method for class 'data.frame'
median_or_mode(x)

Arguments

x

A vector.

Value

A numeric or factor vector of length 1.

See Also

Examples

require("datasets")
# mean for numerics
mean_or_mode(iris)
mean_or_mode(iris[["Sepal.Length"]])
mean_or_mode(iris[["Species"]])

# median for numerics
median_or_mode(iris)

prediction

Tidy, Type-Safe 'prediction()' Methods

v0.3.14
MIT + file LICENSE
Authors
Thomas J. Leeper [aut, cre] (<https://orcid.org/0000-0003-4097-6326>), Carl Ganz [ctb], Vincent Arel-Bundock [ctb] (<https://orcid.org/0000-0003-2042-7063>)
Initial release
2019-06-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.