[QUERY] Using Mode in R?


Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #3129

    For calculation of mean and median we have built-in functions in R.
    But for mode calculations we do not have any built-in function.
    I had googled and found a piece of code ( code attached below) that can be used to find mode, however, it has a lot of limitations. does anyone know any other easier way to calculate mode in R? like a packadge installation.

    Thanks in advance.


    This is the Code i found on the net, But the limitation of the below code is that, CalMode(1:5) gives 1 and CalMode(5:1) gives 5 so when all the numbers have same freq, the code fails.

    Mode <- function(x) {
    ux <- unique(x)
    ux[which.max(tabulate(match(x, ux)))]

    Changyue Song


    Mode = function(x) {
    tab = table(x)
    md = which(tab == max(tab))
    William Schmitz

    I am trying to find the mode in R for a homework assignment (ISyE 412).  By inspection, I see that the data in the vector is trimodal.  This data vector is small.  I tried the above suggested method from the post as well as the website https://www.tutorialspoint.com/r/r_mean_median_mode.htm.  This yielded only one answer.

    My question is: how do we get bimodal and trimodal results when using R?  With very large data sets, the above method may be problematic.

    I appreciate any suggestions?

    Wenjun Zhu

    Reply to William Schmitz of #3240:

    When the data set is small, we can also try in a shorter and simpler way:



    When the data set is very large, we can apply MapReduce and Hadoop in R. Attached below are my personal points. Hope can help you!

    You must be logged in to view attached files.
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Share this post