How to find the statistical mode

0 votes
Mean() and median() are common R functions that perform as expected. mode() returns the object's internal storage mode, not the value that appears the most in its argument. Is there, however, a standard library method for implementing statistical mode for a vector (or list)?
Jun 10 in Data Analytics by Avinash
• 1,260 points
17 views

1 answer to this question.

0 votes
There is one more option that applies to both character and numeric data:

ux[which.max(tabulate(match(x, ux)))] mode - function(x) ux - unique(x) ux
That can produce a 10M-integer vector and determine its mode on my puny little PC in approximately 30 seconds.

The above method adopts the same strategy as which.max and delivers the first value of the set of modes if your data source is likely to have multiple modes. Use this variation (provided by @digEmAll in the comments) to return all modes:

Tabulate (match (x, ux)) ux[tab == max(tab)] Modes - function(x) - ux - unique(x)
}
answered Jun 24 by Sohail
• 2,960 points

Related Questions In Data Analytics

0 votes
1 answer

How to find out the sum/mean for multiple variables per group in R?

You can use the reshape2 package for ...READ MORE

answered Apr 12, 2018 in Data Analytics by DataKing99
• 8,240 points
2,617 views
0 votes
1 answer

How to find out the package version which is loaded in R?

You can use sessionInfo() to accomplish that. > ...READ MORE

answered Apr 18, 2018 in Data Analytics by zombie
• 3,790 points
234 views
+1 vote
2 answers
0 votes
1 answer

How to find the difference wrt previous value in list/vector?

diff() function returns the difference between numbers ...READ MORE

answered Oct 16, 2019 in Data Analytics by Cherukuri
• 33,010 points
190 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,610 points
437 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
481 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
4,351 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
504 views
0 votes
1 answer

How to use the strsplit function with a period

Since the dot has a specific meaning ...READ MORE

answered Jun 24 in Data Analytics by Sohail
• 2,960 points
18 views
0 votes
1 answer

How to use the switch statement in R functions?

Switch definitely wasn't intended to operate this ...READ MORE

answered Jun 24 in Data Analytics by Sohail
• 2,960 points
21 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP