Returns the element that occurs most frequently in a vector.
calculate_mode(x, na.rm = TRUE)A single value giving the modal element of x.
If two or more values are tied for the highest frequency,
the first one encountered in x is returned.
Internally the function:
Optionally removes NAs (na.rm = TRUE).
Builds a lookup table of unique values via unique(x).
Counts the frequency of each unique value with
tabulate(match(x, ux)).
Returns the value with the maximum count.
Because it relies on base R functions, the implementation is vectorised and generally fast for typical data-frame column sizes.