Populate a list with missing members of a sequence

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











up vote
3
down vote

favorite












I have a collection of lists containing random elements of a sequence, say integers from 0 to 3.



sequence=0., 1., 2., 3.;
Table[RandomSample[sequence, RandomInteger[1, 4]], 5]



3., 0., 1., 3., 1., 0., 2., 1., 3., 1., 3., 0., 2., 0., 2.,
3.




How do I populate the lists so that the missing sequence members are filled?




3., 0., 1., 2., 3., 1., 0., 2., 1., 3., 0., 2., 1., 3., 0.,
2., 0., 2., 3., 1.




Note: answers where elements are Integers are fine but I'm also looking for answers which work for Real elements.










share|improve this question

























    up vote
    3
    down vote

    favorite












    I have a collection of lists containing random elements of a sequence, say integers from 0 to 3.



    sequence=0., 1., 2., 3.;
    Table[RandomSample[sequence, RandomInteger[1, 4]], 5]



    3., 0., 1., 3., 1., 0., 2., 1., 3., 1., 3., 0., 2., 0., 2.,
    3.




    How do I populate the lists so that the missing sequence members are filled?




    3., 0., 1., 2., 3., 1., 0., 2., 1., 3., 0., 2., 1., 3., 0.,
    2., 0., 2., 3., 1.




    Note: answers where elements are Integers are fine but I'm also looking for answers which work for Real elements.










    share|improve this question























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I have a collection of lists containing random elements of a sequence, say integers from 0 to 3.



      sequence=0., 1., 2., 3.;
      Table[RandomSample[sequence, RandomInteger[1, 4]], 5]



      3., 0., 1., 3., 1., 0., 2., 1., 3., 1., 3., 0., 2., 0., 2.,
      3.




      How do I populate the lists so that the missing sequence members are filled?




      3., 0., 1., 2., 3., 1., 0., 2., 1., 3., 0., 2., 1., 3., 0.,
      2., 0., 2., 3., 1.




      Note: answers where elements are Integers are fine but I'm also looking for answers which work for Real elements.










      share|improve this question













      I have a collection of lists containing random elements of a sequence, say integers from 0 to 3.



      sequence=0., 1., 2., 3.;
      Table[RandomSample[sequence, RandomInteger[1, 4]], 5]



      3., 0., 1., 3., 1., 0., 2., 1., 3., 1., 3., 0., 2., 0., 2.,
      3.




      How do I populate the lists so that the missing sequence members are filled?




      3., 0., 1., 2., 3., 1., 0., 2., 1., 3., 0., 2., 1., 3., 0.,
      2., 0., 2., 3., 1.




      Note: answers where elements are Integers are fine but I'm also looking for answers which work for Real elements.







      list-manipulation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 23 at 17:14









      Musang

      7341618




      7341618




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          7
          down vote



          accepted










          This should work for any kind of list, not just numeric ones :)



          sequence = 0., 1., 2., 3.;
          list = Table[RandomSample[sequence, RandomInteger[1, 4]], 5]



          2., 0., 0., 3., 2., 0., 3., 1., 1., 0., 2., 3.




          #~Join~Complement[sequence, #] & /@ list



          2., 0., 1., 3., 0., 3., 1., 2., 2., 0., 1., 3., 0., 3., 1.,
          2., 1., 0., 2., 3.







          share|improve this answer
















          • 1




            I could have sworn I looked for that Complement function in the docs... Nice one-liner!
            – Musang
            Aug 23 at 19:26










          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%2f180528%2fpopulate-a-list-with-missing-members-of-a-sequence%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
          7
          down vote



          accepted










          This should work for any kind of list, not just numeric ones :)



          sequence = 0., 1., 2., 3.;
          list = Table[RandomSample[sequence, RandomInteger[1, 4]], 5]



          2., 0., 0., 3., 2., 0., 3., 1., 1., 0., 2., 3.




          #~Join~Complement[sequence, #] & /@ list



          2., 0., 1., 3., 0., 3., 1., 2., 2., 0., 1., 3., 0., 3., 1.,
          2., 1., 0., 2., 3.







          share|improve this answer
















          • 1




            I could have sworn I looked for that Complement function in the docs... Nice one-liner!
            – Musang
            Aug 23 at 19:26














          up vote
          7
          down vote



          accepted










          This should work for any kind of list, not just numeric ones :)



          sequence = 0., 1., 2., 3.;
          list = Table[RandomSample[sequence, RandomInteger[1, 4]], 5]



          2., 0., 0., 3., 2., 0., 3., 1., 1., 0., 2., 3.




          #~Join~Complement[sequence, #] & /@ list



          2., 0., 1., 3., 0., 3., 1., 2., 2., 0., 1., 3., 0., 3., 1.,
          2., 1., 0., 2., 3.







          share|improve this answer
















          • 1




            I could have sworn I looked for that Complement function in the docs... Nice one-liner!
            – Musang
            Aug 23 at 19:26












          up vote
          7
          down vote



          accepted







          up vote
          7
          down vote



          accepted






          This should work for any kind of list, not just numeric ones :)



          sequence = 0., 1., 2., 3.;
          list = Table[RandomSample[sequence, RandomInteger[1, 4]], 5]



          2., 0., 0., 3., 2., 0., 3., 1., 1., 0., 2., 3.




          #~Join~Complement[sequence, #] & /@ list



          2., 0., 1., 3., 0., 3., 1., 2., 2., 0., 1., 3., 0., 3., 1.,
          2., 1., 0., 2., 3.







          share|improve this answer












          This should work for any kind of list, not just numeric ones :)



          sequence = 0., 1., 2., 3.;
          list = Table[RandomSample[sequence, RandomInteger[1, 4]], 5]



          2., 0., 0., 3., 2., 0., 3., 1., 1., 0., 2., 3.




          #~Join~Complement[sequence, #] & /@ list



          2., 0., 1., 3., 0., 3., 1., 2., 2., 0., 1., 3., 0., 3., 1.,
          2., 1., 0., 2., 3.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 23 at 17:18









          Fraccalo

          2,219517




          2,219517







          • 1




            I could have sworn I looked for that Complement function in the docs... Nice one-liner!
            – Musang
            Aug 23 at 19:26












          • 1




            I could have sworn I looked for that Complement function in the docs... Nice one-liner!
            – Musang
            Aug 23 at 19:26







          1




          1




          I could have sworn I looked for that Complement function in the docs... Nice one-liner!
          – Musang
          Aug 23 at 19:26




          I could have sworn I looked for that Complement function in the docs... Nice one-liner!
          – Musang
          Aug 23 at 19:26

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f180528%2fpopulate-a-list-with-missing-members-of-a-sequence%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay