I have the following code but don't fully understand it, as I am relatively new to R.
mode <- function(x){
ta<-table(x)
tam <- max(ta)
if (all(ta==tam))
mod <- NA
else if(is.numeric(x))
mod <- as.numeric(names(ta)[ta==tam])
else
mod <- names(ta)[ta==tam]
return(mod)
}
Can someone please explain what is happening under the else if and else segments of the code?
Thanks!