Learn R Programming

prediction (version 0.3.17)

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)

# S3 method for default mean_or_mode(x)

# S3 method for numeric mean_or_mode(x)

# S3 method for data.frame mean_or_mode(x)

median_or_mode(x)

# S3 method for default median_or_mode(x)

# S3 method for numeric median_or_mode(x)

# S3 method for data.frame median_or_mode(x)

Value

A numeric or factor vector of length 1.

Arguments

x

A vector.

See Also

prediction, build_datalist, seq_range

Examples

Run this code
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)

Run the code above in your browser using DataLab