centralValue {dataReporter} | R Documentation |
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, (have_)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
|
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
#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))))