Skip to content

Instantly share code, notes, and snippets.

@ptompalski
Created March 7, 2016 05:10
Show Gist options
  • Save ptompalski/6ea3cecc3c0d4b3af69a to your computer and use it in GitHub Desktop.
Save ptompalski/6ea3cecc3c0d4b3af69a to your computer and use it in GitHub Desktop.
calculate mode (most frequent value) in R
mode <- function(x) {
if(is.numeric(x)) { x <- round(x,2)}
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment