

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find mode(s) of a vector in R?
Just like mean and median there is no in-built function in R to find the mode.
We can make use of the following user created function for this purpose
> Modes <- function(x) { ux <- unique(x) tab <- tabulate(match(x, ux)) ux[tab == max(tab)] }
Example
> x<-c(3,2,3,4,3,2,1,2,3,45,6,7,6,4,3,32,4,5,6,4,4,3,4,5,4,4,3,6) > Modes(x) [1] 4
We have created a function called modes because a data can have more than one mode as shown below −
> y<-c(3,2,3,4,3,2,1,2,3,45,6,7,6,4,3,32,4,5,6,4,4,3,4,5,4,4,3,3) > Modes(y) [1] 3 4
- Related Questions & Answers
- How to find the range of a vector in R?
- How to find the row-wise mode of a matrix in R?
- How to find the root mean square of a vector in R?
- How to find the length of sequence vector in R?
- How to find the index of an element in a vector in R?
- How to find the intersection of elements in a string vector in R?
- How to find similar words in vector of strings in R?
- How to find the rate of return for a vector values in R?
- How to find all combinations of a vector elements without space in R?
- How to find the position of NA in an R vector?
- How to create a vector of lists in R?
- How to create a vector of matrices in R?
- How to find the count of a particular character in a string vector in R?
- How to reverse a vector in R?
- How to find the position of a non-NA value in an R vector?
Advertisements