I have an array
a <- c(1,1,1,1,1,2,3,4,5,5,5,5,5,6,7,7,7,7)
I would like to use some command that would tell me which is the most frequent number in the array?
is there a simple command for this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
table()function is sufficient for this, and particularly useful if your data have more than one mode.Consider the following options, all related to
table()andmax().As indicated in the comments, in some cases you might want to see the two or three most commonly occurring values, in which case
sort()is useful:You can also set a threshold for which values to return in your table. For instance, if you wanted to return only those numbers which occurred more than once: