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

View source: R/aided_chatgpt.R

mode.calcR Documentation

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)

Arguments

x

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

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.

Examples

# 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)


quickcode documentation built on April 11, 2025, 5:49 p.m.