centralValue: summaryFunction for central values

Description Usage Arguments Details Value See Also Examples

View source: R/centralValue.R

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, (have_)labelled, Date and logical variables, the central value is the mode (i.e. the value that occurs the largest number of times).

Usage

1

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.

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 (haven_)labelled variables. No values are ignored for logical variables.

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.

See Also

summaryFunction, summarize, summaryResult, allSummaryFunctions

Examples

1
2
3
4
5
 #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))))

dataMaid documentation built on Oct. 8, 2021, 9:08 a.m.