get_mode | R Documentation |
This utility calculates the mode (i.e. the most frequently observed value) for a vector of values. The function function includes an option (see "ties" argument) to return more than one value if there are ties when calculating the mode.
get_mode(x, ties = TRUE)
x |
Vector for which the mode should be calculated |
ties |
Boolean indicating whether or not ties for mode should be returned; if |
The mode returned is calculated by tabulating the frequency of each element in the input vector. Note that this method allows for non-numeric vectors to be passed to the function. For example, the function would return the "mode" for a character vector as the most frequently observed string.
A vector containing the most frequently observed values in the x
vector. If there are ties in the mode and the "ties" argument is set to TRUE
, then the length of the returned vector will be greater than 1. If not, then the length of the returned vector will be 1.
get_mode(c(1,1,4,3,2,2,2,2)) get_mode(c("dog","dog","dog","monkey", "rat")) get_mode(c(1,1,1,1,4,3,2,2,2,2), ties = TRUE) get_mode(c(1,1,1,1,4,3,2,2,2,2), ties = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.