Learn R Programming

dataMaid (version 1.0.0)

centralValue: summaryFunction for central values

Description

A summaryFunction, intended to be called from summarize, which returns the central value of a variable. For numeric and integer variables, this is the median. For character, factor, labelled, Date and logical variables, the central value is the mode (i.e. the value that occurs the largest number of times).

Usage

centralValue(v, ...)

Arguments

v

A variable (vector).

...

Extra arguments to be passed to class-specific functions. These incluse maxDecimals (default is 2) which controls the rounding of integer and numeric values.

Value

An object of class summaryResult with the following entries: $feature (the mode/median),$result (the central value of v) and $value (identical to $result).

If the mode is returned and it is not uniquely determined, the first value qualifying as a mode is returned, when the variable is sorted according to sort.

Details

Note that NA, NaN and Inf values are ignored for numeric and integer variables, while only NA values are ignored for factor, character, Date and labelled variables. No values are ignored for logical variables.

See Also

summaryFunction, summarize, summaryResult, allSummaryFunctions

Examples

Run this code
# NOT RUN {
 #central value of an integer variable:
   centralValue(c(rep(1, 25), rep(2, 10), rep(3, 20)))

 #central value of a character variable:
   centralValue(as.character(c(rep(1, 20), rep(2, 10), rep(3, 20))))

# }

Run the code above in your browser using DataLab