Modal value with deterministic tie-break (default categorical aggregator)
imputeMode.RdReturns the most frequent value in x. Used as the built-in default
for imputeMissingCovariates()'s categoricalFn argument, and
exposed publicly so callers can plug it into their own workflows or
compose it with other rules.
Arguments
- x
A non-empty atomic vector (character, factor, numeric, integer, or logical). Length-0 input errors.
- missingToken
Optional atomic vector of sentinel values to exclude from the candidate set (compared after
as.character()on both sides). DefaultNULLmeans no values are excluded.
Details
Properties:
Deterministic tie-break. When two or more values tie for the highest frequency, the one that appears first in
xwins. This makes the result stable across runs and independent of locale- sensitive ordering insidetable().Factor-preserving. If
xis a factor, the return value is a factor with the samelevels(x). Plain character / numeric vectors return a length-1 value of the same atomic type.NA-tolerant.NAentries are ignored when computing the mode. If every entry isNAthe function errors.Optional token avoidance. When
missingTokenis supplied, values matching any element of it are excluded from the candidate set.imputeMissingCovariates()masks the input pool up-front so this is normally a no-op there; the parameter is useful when callingimputeMode()standalone on a raw vector that may still contain sentinels.