Function for most frequent level of string or factor categorical variable in R
Your function isn't very complicated so I don't know how much more efficient you can get.  However, maybe removing the if and else states may help.  How about something like this?

Code

# Sample Data
dat &lt;- c("a", "a", "b", "c", "d","a", "a", "b", "c", "d","a", "a", "b", "c", "d","a", "a", "b", "c", "d","a", "a", "b", "c", "d")

# Mode function
MaxTable &lt;- function(x){
     dd &lt;- unique(x)
     dd[which.max(tabulate(match(x,dd)))]
}


Output

&gt; MaxTable(dat)

[1] "a"


How many variables are you trying to process? You may want to think about writing a function that splits up the number of obs. for parallel processing, tabulate the mode for each section, merge each section, and then do which.max() .  Although, I'm not sure if you are reaching the limits of R.  Also, maybe a database such as mysql would be another option.