Learn R Programming

quickcode (version 1.0.6)

mode.calc: Calculate the Mode of a Numeric or Character Vector

Description

This function calculates the mode (most frequently occurring value(s)) of a numeric or character vector.

Usage

mode.calc(x)

Value

The mode(s) of the input vector. If multiple values have the same highest frequency, all modes are returned. Returns `NA` if the input vector is empty.

Arguments

x

A numeric or character vector for which the mode is to be calculated.

Examples

Run this code
# Example with a numeric vector
numeric_vector <- c(1, 2, 2, 3, 3, 3, 4, 5)
mode.calc(numeric_vector)

# Example with a character vector
character_vector <- c("apple", "banana", "apple", "orange", "banana", "banana")
mode.calc(character_vector)

Run the code above in your browser using DataLab