How to find items tied for most appearances in a list?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
8
down vote

favorite












I want to create a list of the items in list w tied for appearing the most times in w. In other words, if 22 appears in w more than any other number, I want the result to be 22. If 34 and 55 appear the most times in w but the same number of times, I want the result to be 34,55.



The example below just uses a randomly generated list w. My method works but is ugly and inefficient.



w = RandomInteger[100, 200]
fw = w // DeleteDuplicates
wc = Counts[w]
m = Max[fw /. wc]
Reap[Do[If[(fw[[i]] /. wc) == m, Sow[fw[[i]]]], i, 1, Length[fw]]][[2, 1]]


Is there a tidier way?










share|improve this question



























    up vote
    8
    down vote

    favorite












    I want to create a list of the items in list w tied for appearing the most times in w. In other words, if 22 appears in w more than any other number, I want the result to be 22. If 34 and 55 appear the most times in w but the same number of times, I want the result to be 34,55.



    The example below just uses a randomly generated list w. My method works but is ugly and inefficient.



    w = RandomInteger[100, 200]
    fw = w // DeleteDuplicates
    wc = Counts[w]
    m = Max[fw /. wc]
    Reap[Do[If[(fw[[i]] /. wc) == m, Sow[fw[[i]]]], i, 1, Length[fw]]][[2, 1]]


    Is there a tidier way?










    share|improve this question

























      up vote
      8
      down vote

      favorite









      up vote
      8
      down vote

      favorite











      I want to create a list of the items in list w tied for appearing the most times in w. In other words, if 22 appears in w more than any other number, I want the result to be 22. If 34 and 55 appear the most times in w but the same number of times, I want the result to be 34,55.



      The example below just uses a randomly generated list w. My method works but is ugly and inefficient.



      w = RandomInteger[100, 200]
      fw = w // DeleteDuplicates
      wc = Counts[w]
      m = Max[fw /. wc]
      Reap[Do[If[(fw[[i]] /. wc) == m, Sow[fw[[i]]]], i, 1, Length[fw]]][[2, 1]]


      Is there a tidier way?










      share|improve this question















      I want to create a list of the items in list w tied for appearing the most times in w. In other words, if 22 appears in w more than any other number, I want the result to be 22. If 34 and 55 appear the most times in w but the same number of times, I want the result to be 34,55.



      The example below just uses a randomly generated list w. My method works but is ugly and inefficient.



      w = RandomInteger[100, 200]
      fw = w // DeleteDuplicates
      wc = Counts[w]
      m = Max[fw /. wc]
      Reap[Do[If[(fw[[i]] /. wc) == m, Sow[fw[[i]]]], i, 1, Length[fw]]][[2, 1]]


      Is there a tidier way?







      list-manipulation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday

























      asked 2 days ago









      Jerry Guern

      1,954732




      1,954732




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          9
          down vote



          accepted










          You need Commonest:



          SeedRandom[1]
          w = RandomInteger[100, 200];

          Commonest[w]



          68, 25, 63




          % /. Counts[w]



          5, 5, 5







          share|improve this answer






















          • Thank you! The first part is exactly what I need. But you could explain how the syntax of the second part works? I don't even know how to look that up.
            – Jerry Guern
            2 days ago






          • 1




            @JerryGuern, thank you for the accept. About the last line: it gives the same result as 68, 25, 63 /. Counts[w]. % stands for the last result generated . (See Out (%) in the docs.) So the last line is the same as Count[w, #]&/@ 68,25,63. See also: Map (/@), Function (&) and Slot (#).
            – kglr
            2 days ago











          • Okay, thanks for the followup and links.
            – Jerry Guern
            yesterday










          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "387"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181652%2fhow-to-find-items-tied-for-most-appearances-in-a-list%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          9
          down vote



          accepted










          You need Commonest:



          SeedRandom[1]
          w = RandomInteger[100, 200];

          Commonest[w]



          68, 25, 63




          % /. Counts[w]



          5, 5, 5







          share|improve this answer






















          • Thank you! The first part is exactly what I need. But you could explain how the syntax of the second part works? I don't even know how to look that up.
            – Jerry Guern
            2 days ago






          • 1




            @JerryGuern, thank you for the accept. About the last line: it gives the same result as 68, 25, 63 /. Counts[w]. % stands for the last result generated . (See Out (%) in the docs.) So the last line is the same as Count[w, #]&/@ 68,25,63. See also: Map (/@), Function (&) and Slot (#).
            – kglr
            2 days ago











          • Okay, thanks for the followup and links.
            – Jerry Guern
            yesterday














          up vote
          9
          down vote



          accepted










          You need Commonest:



          SeedRandom[1]
          w = RandomInteger[100, 200];

          Commonest[w]



          68, 25, 63




          % /. Counts[w]



          5, 5, 5







          share|improve this answer






















          • Thank you! The first part is exactly what I need. But you could explain how the syntax of the second part works? I don't even know how to look that up.
            – Jerry Guern
            2 days ago






          • 1




            @JerryGuern, thank you for the accept. About the last line: it gives the same result as 68, 25, 63 /. Counts[w]. % stands for the last result generated . (See Out (%) in the docs.) So the last line is the same as Count[w, #]&/@ 68,25,63. See also: Map (/@), Function (&) and Slot (#).
            – kglr
            2 days ago











          • Okay, thanks for the followup and links.
            – Jerry Guern
            yesterday












          up vote
          9
          down vote



          accepted







          up vote
          9
          down vote



          accepted






          You need Commonest:



          SeedRandom[1]
          w = RandomInteger[100, 200];

          Commonest[w]



          68, 25, 63




          % /. Counts[w]



          5, 5, 5







          share|improve this answer














          You need Commonest:



          SeedRandom[1]
          w = RandomInteger[100, 200];

          Commonest[w]



          68, 25, 63




          % /. Counts[w]



          5, 5, 5








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered 2 days ago









          kglr

          159k8184384




          159k8184384











          • Thank you! The first part is exactly what I need. But you could explain how the syntax of the second part works? I don't even know how to look that up.
            – Jerry Guern
            2 days ago






          • 1




            @JerryGuern, thank you for the accept. About the last line: it gives the same result as 68, 25, 63 /. Counts[w]. % stands for the last result generated . (See Out (%) in the docs.) So the last line is the same as Count[w, #]&/@ 68,25,63. See also: Map (/@), Function (&) and Slot (#).
            – kglr
            2 days ago











          • Okay, thanks for the followup and links.
            – Jerry Guern
            yesterday
















          • Thank you! The first part is exactly what I need. But you could explain how the syntax of the second part works? I don't even know how to look that up.
            – Jerry Guern
            2 days ago






          • 1




            @JerryGuern, thank you for the accept. About the last line: it gives the same result as 68, 25, 63 /. Counts[w]. % stands for the last result generated . (See Out (%) in the docs.) So the last line is the same as Count[w, #]&/@ 68,25,63. See also: Map (/@), Function (&) and Slot (#).
            – kglr
            2 days ago











          • Okay, thanks for the followup and links.
            – Jerry Guern
            yesterday















          Thank you! The first part is exactly what I need. But you could explain how the syntax of the second part works? I don't even know how to look that up.
          – Jerry Guern
          2 days ago




          Thank you! The first part is exactly what I need. But you could explain how the syntax of the second part works? I don't even know how to look that up.
          – Jerry Guern
          2 days ago




          1




          1




          @JerryGuern, thank you for the accept. About the last line: it gives the same result as 68, 25, 63 /. Counts[w]. % stands for the last result generated . (See Out (%) in the docs.) So the last line is the same as Count[w, #]&/@ 68,25,63. See also: Map (/@), Function (&) and Slot (#).
          – kglr
          2 days ago





          @JerryGuern, thank you for the accept. About the last line: it gives the same result as 68, 25, 63 /. Counts[w]. % stands for the last result generated . (See Out (%) in the docs.) So the last line is the same as Count[w, #]&/@ 68,25,63. See also: Map (/@), Function (&) and Slot (#).
          – kglr
          2 days ago













          Okay, thanks for the followup and links.
          – Jerry Guern
          yesterday




          Okay, thanks for the followup and links.
          – Jerry Guern
          yesterday

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181652%2fhow-to-find-items-tied-for-most-appearances-in-a-list%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery