swh:1:snp:81eadaa089e8253d8469bcef66aa332632c6c669
Tip revision: c79a04b5074656b36e591191eb8137b70a349932 authored by Hans W. Borchers on 30 June 2014, 00:00:00 UTC
version 1.7.0
version 1.7.0
Tip revision: c79a04b
mode.R
##
## m o d e . R
##
Mode <- function(x) {
if (is.matrix(x))
x <- c(x)
if (is.numeric(x)) {
x <- sort(x)
tbl <- table(x)
n <- which.max(tbl)
xm <- as.numeric(names(tbl)[n])
} else if (is.complex(x)) {
x <- x[order(abs(x))]
tbl <- table(x)
n <- which.max(tbl)
xm <- as.complex(names(tbl)[n])
} else if (is.factor(x)) {
tbl <- table(x)
n <- which.max(tbl)
xm <- names(tbl)[n]
} else
xm <- NA
return(xm)
}