Select Years with the Greatest Number of Repeatedly Sampled Sites in R











up vote
0
down vote

favorite












I have many sites that were sampled over many "Season-Year" combinations (time column). I want to select Season-Year combinations that have 10 or more of the same sites. Data is at the bottom of this post. Any thoughts for making this work?



Code I have tried that didn't work:



subset1 <- tbl_df(coords) %>%
group_by(SznYr) %>%
tally(SiteID) %>%
top_n(10)

subset2 <- tbl_df(coords) %>% group_by(SznYr) %>% top_n(2, SiteID)


The data is in this googledoc link -- https://docs.google.com/document/d/1SsTIZwJBGGqeaz7VyH7lh9mLc8XQJ4b9gEnQ_3hWzj4/edit?usp=sharing










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have many sites that were sampled over many "Season-Year" combinations (time column). I want to select Season-Year combinations that have 10 or more of the same sites. Data is at the bottom of this post. Any thoughts for making this work?



    Code I have tried that didn't work:



    subset1 <- tbl_df(coords) %>%
    group_by(SznYr) %>%
    tally(SiteID) %>%
    top_n(10)

    subset2 <- tbl_df(coords) %>% group_by(SznYr) %>% top_n(2, SiteID)


    The data is in this googledoc link -- https://docs.google.com/document/d/1SsTIZwJBGGqeaz7VyH7lh9mLc8XQJ4b9gEnQ_3hWzj4/edit?usp=sharing










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have many sites that were sampled over many "Season-Year" combinations (time column). I want to select Season-Year combinations that have 10 or more of the same sites. Data is at the bottom of this post. Any thoughts for making this work?



      Code I have tried that didn't work:



      subset1 <- tbl_df(coords) %>%
      group_by(SznYr) %>%
      tally(SiteID) %>%
      top_n(10)

      subset2 <- tbl_df(coords) %>% group_by(SznYr) %>% top_n(2, SiteID)


      The data is in this googledoc link -- https://docs.google.com/document/d/1SsTIZwJBGGqeaz7VyH7lh9mLc8XQJ4b9gEnQ_3hWzj4/edit?usp=sharing










      share|improve this question













      I have many sites that were sampled over many "Season-Year" combinations (time column). I want to select Season-Year combinations that have 10 or more of the same sites. Data is at the bottom of this post. Any thoughts for making this work?



      Code I have tried that didn't work:



      subset1 <- tbl_df(coords) %>%
      group_by(SznYr) %>%
      tally(SiteID) %>%
      top_n(10)

      subset2 <- tbl_df(coords) %>% group_by(SznYr) %>% top_n(2, SiteID)


      The data is in this googledoc link -- https://docs.google.com/document/d/1SsTIZwJBGGqeaz7VyH7lh9mLc8XQJ4b9gEnQ_3hWzj4/edit?usp=sharing







      r dplyr data-manipulation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 21:37









      jabby corbs

      163




      163
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          We can use count and then filter for n >= 10. However, as you can see in the following, the maximum count number is only 3. I don't think you can find a SznYr with 10 or more than 10 counts.



          coords %>%
          count(SITEID, SznYr) %>%
          arrange(desc(n))
          # # A tibble: 2,013 x 3
          # SITEID SznYr n
          # <fct> <fct> <int>
          # 1 SB506 1994-Summer 3
          # 2 SB506 1995-Summer 3
          # 3 SB506 1996-Spring 3
          # 4 SB267 1994-Fall 2
          # 5 SB267 1995-Winter 2
          # 6 SB357 1995-Summer 2
          # 7 SB367 1995-Summer 2
          # 8 SB368 1994-Fall 2
          # 9 SB368 1995-Fall 2
          # 10 SB407 1993-Winter 2
          # # ... with 2,003 more rows





          share|improve this answer























          • Thanks for your response! However, this doesn't look like it does what I was hoping it would do. Should I clarify?
            – jabby corbs
            Nov 7 at 23:43












          • Yes, please clarify.
            – www
            Nov 8 at 0:18










          • I believe this answers the question asked.
            – Nettle
            Nov 8 at 3:45











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53198208%2fselect-years-with-the-greatest-number-of-repeatedly-sampled-sites-in-r%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          We can use count and then filter for n >= 10. However, as you can see in the following, the maximum count number is only 3. I don't think you can find a SznYr with 10 or more than 10 counts.



          coords %>%
          count(SITEID, SznYr) %>%
          arrange(desc(n))
          # # A tibble: 2,013 x 3
          # SITEID SznYr n
          # <fct> <fct> <int>
          # 1 SB506 1994-Summer 3
          # 2 SB506 1995-Summer 3
          # 3 SB506 1996-Spring 3
          # 4 SB267 1994-Fall 2
          # 5 SB267 1995-Winter 2
          # 6 SB357 1995-Summer 2
          # 7 SB367 1995-Summer 2
          # 8 SB368 1994-Fall 2
          # 9 SB368 1995-Fall 2
          # 10 SB407 1993-Winter 2
          # # ... with 2,003 more rows





          share|improve this answer























          • Thanks for your response! However, this doesn't look like it does what I was hoping it would do. Should I clarify?
            – jabby corbs
            Nov 7 at 23:43












          • Yes, please clarify.
            – www
            Nov 8 at 0:18










          • I believe this answers the question asked.
            – Nettle
            Nov 8 at 3:45















          up vote
          0
          down vote













          We can use count and then filter for n >= 10. However, as you can see in the following, the maximum count number is only 3. I don't think you can find a SznYr with 10 or more than 10 counts.



          coords %>%
          count(SITEID, SznYr) %>%
          arrange(desc(n))
          # # A tibble: 2,013 x 3
          # SITEID SznYr n
          # <fct> <fct> <int>
          # 1 SB506 1994-Summer 3
          # 2 SB506 1995-Summer 3
          # 3 SB506 1996-Spring 3
          # 4 SB267 1994-Fall 2
          # 5 SB267 1995-Winter 2
          # 6 SB357 1995-Summer 2
          # 7 SB367 1995-Summer 2
          # 8 SB368 1994-Fall 2
          # 9 SB368 1995-Fall 2
          # 10 SB407 1993-Winter 2
          # # ... with 2,003 more rows





          share|improve this answer























          • Thanks for your response! However, this doesn't look like it does what I was hoping it would do. Should I clarify?
            – jabby corbs
            Nov 7 at 23:43












          • Yes, please clarify.
            – www
            Nov 8 at 0:18










          • I believe this answers the question asked.
            – Nettle
            Nov 8 at 3:45













          up vote
          0
          down vote










          up vote
          0
          down vote









          We can use count and then filter for n >= 10. However, as you can see in the following, the maximum count number is only 3. I don't think you can find a SznYr with 10 or more than 10 counts.



          coords %>%
          count(SITEID, SznYr) %>%
          arrange(desc(n))
          # # A tibble: 2,013 x 3
          # SITEID SznYr n
          # <fct> <fct> <int>
          # 1 SB506 1994-Summer 3
          # 2 SB506 1995-Summer 3
          # 3 SB506 1996-Spring 3
          # 4 SB267 1994-Fall 2
          # 5 SB267 1995-Winter 2
          # 6 SB357 1995-Summer 2
          # 7 SB367 1995-Summer 2
          # 8 SB368 1994-Fall 2
          # 9 SB368 1995-Fall 2
          # 10 SB407 1993-Winter 2
          # # ... with 2,003 more rows





          share|improve this answer














          We can use count and then filter for n >= 10. However, as you can see in the following, the maximum count number is only 3. I don't think you can find a SznYr with 10 or more than 10 counts.



          coords %>%
          count(SITEID, SznYr) %>%
          arrange(desc(n))
          # # A tibble: 2,013 x 3
          # SITEID SznYr n
          # <fct> <fct> <int>
          # 1 SB506 1994-Summer 3
          # 2 SB506 1995-Summer 3
          # 3 SB506 1996-Spring 3
          # 4 SB267 1994-Fall 2
          # 5 SB267 1995-Winter 2
          # 6 SB357 1995-Summer 2
          # 7 SB367 1995-Summer 2
          # 8 SB368 1994-Fall 2
          # 9 SB368 1995-Fall 2
          # 10 SB407 1993-Winter 2
          # # ... with 2,003 more rows






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 7 at 22:08

























          answered Nov 7 at 21:58









          www

          25.5k102240




          25.5k102240












          • Thanks for your response! However, this doesn't look like it does what I was hoping it would do. Should I clarify?
            – jabby corbs
            Nov 7 at 23:43












          • Yes, please clarify.
            – www
            Nov 8 at 0:18










          • I believe this answers the question asked.
            – Nettle
            Nov 8 at 3:45


















          • Thanks for your response! However, this doesn't look like it does what I was hoping it would do. Should I clarify?
            – jabby corbs
            Nov 7 at 23:43












          • Yes, please clarify.
            – www
            Nov 8 at 0:18










          • I believe this answers the question asked.
            – Nettle
            Nov 8 at 3:45
















          Thanks for your response! However, this doesn't look like it does what I was hoping it would do. Should I clarify?
          – jabby corbs
          Nov 7 at 23:43






          Thanks for your response! However, this doesn't look like it does what I was hoping it would do. Should I clarify?
          – jabby corbs
          Nov 7 at 23:43














          Yes, please clarify.
          – www
          Nov 8 at 0:18




          Yes, please clarify.
          – www
          Nov 8 at 0:18












          I believe this answers the question asked.
          – Nettle
          Nov 8 at 3:45




          I believe this answers the question asked.
          – Nettle
          Nov 8 at 3:45


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53198208%2fselect-years-with-the-greatest-number-of-repeatedly-sampled-sites-in-r%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings