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).
centralValue(v, ...)
v | A variable (vector). |
---|---|
... | Extra arguments to be passed to class-specific functions. These incluse
|
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
.
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.
#central value of an integer variable: centralValue(c(rep(1, 25), rep(2, 10), rep(3, 20)))#> Median: 2#central value of a character variable: centralValue(as.character(c(rep(1, 20), rep(2, 10), rep(3, 20))))#> Mode: "1"