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
r dplyr data-manipulation
add a comment |
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
r dplyr data-manipulation
add a comment |
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
r dplyr data-manipulation
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
r dplyr data-manipulation
asked Nov 7 at 21:37
jabby corbs
163
163
add a comment |
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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