Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8975979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:00:53+00:00 2026-06-15T19:00:53+00:00

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

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:00:54+00:00Added an answer on June 15, 2026 at 7:00 pm

    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() and max().


    # Your vector
    a = c(1,1,1,1,1,2,3,4,5,5,5,5,5,6,7,7,7,7)
    
    # Basic frequency table
    table(a)
    # a
    # 1 2 3 4 5 6 7 
    # 5 1 1 1 5 1 4 
    
    # Only gives me the value for highest frequency
    # Doesn't tell me which number that is though
    max(table(a))
    # [1] 5
    
    # Gives me a logical vector, which might be useful
    # but not what you're asking for in this question
    table(a) == max(table(a))
    # a
    #    1     2     3     4     5     6     7 
    # TRUE FALSE FALSE FALSE  TRUE FALSE FALSE 
    
    # This is probably more like what you're looking for
    which(table(a) == max(table(a)))
    # 1 5 
    # 1 5 
    
    # Or, maybe this
    names(which(table(a) == max(table(a))))
    # [1] "1" "5"
    

    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:

    sort(table(a))
    # a
    # 2 3 4 6 7 1 5 
    # 1 1 1 1 4 5 5 
    

    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:

    sort(table(a)[table(a) > 1])
    # a
    # 7 1 5 
    # 4 5 5 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some simple XML which I would like to parse into an array
I have an SHA-1 byte array that I would like to use in a
I have some dynamic int * arrays that I would like to use as
I have an array of Integers in Java, I would like use only a
I have an array which i would like to sort it based on values
I have an array which i would like to sort it based on values
I have an array that I would like to sort using a date field
i have a function that converts an array to a hash which i would
I have an array and would like to use the same concept as a
If I have a fairly complex User model that I would like to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.