library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0      ✔ purrr   0.3.5 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.5.0 
## ✔ readr   2.1.3      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(dplyr)
library(readr)
MBT_ebird<- read_csv("https://github.com/mbtoomey/Biol_7263/blob/main/Data/MBT_ebird.csv?raw=true")
## New names:
## Rows: 6595 Columns: 14
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (4): list_ID, common_name, scientific_name, location dbl (8): ...1, count,
## duration, latitude, longitude, count_tot, month, year date (1): date time (1):
## time
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`

1. In which year did I observe the most individual birds? How many?

year_data <- group_by(MBT_ebird, year)

summarize(year_data, sum(count))
## # A tibble: 13 × 2
##     year `sum(count)`
##    <dbl>        <dbl>
##  1  2003           49
##  2  2004         1116
##  3  2009           25
##  4  2013          151
##  5  2014         9303
##  6  2015         3219
##  7  2016          379
##  8  2017         6102
##  9  2018         1738
## 10  2019          677
## 11  2020         8941
## 12  2021         3713
## 13  2022         1371

The year you observed the most birds was 2014 when you observed 9303 birds

##2. In that year how many different species of birds did I observe?

species_year <- filter(MBT_ebird, year == 2014)

mutate(species_year, SpeciesNum = n_distinct(scientific_name))
## # A tibble: 1,672 × 15
##     ...1 list_ID  commo…¹ scien…² date       time  count durat…³ locat…⁴ latit…⁵
##    <dbl> <chr>    <chr>   <chr>   <date>     <tim> <dbl>   <dbl> <chr>     <dbl>
##  1    15 S209644… Greate… Anser … 2014-12-20 09:30    30     150 US-MO      38.9
##  2    45 S209644… Canada… Branta… 2014-12-20 09:30    45     150 US-MO      38.9
##  3    50 S178557… Canada… Branta… 2014-04-12 08:45     2     120 US-MO      38.7
##  4    51 S210255… Canada… Branta… 2014-12-25 10:30     8     120 US-MO      38.7
##  5    52 S167719… Canada… Branta… 2014-02-02 16:00   178      30 US-MO      38.6
##  6    53 S165368… Canada… Branta… 2014-01-27 14:30    70      45 US-MO      38.6
##  7    54 S172237… Canada… Branta… 2014-02-27 08:40    56      45 US-MO      38.6
##  8    55 S172940… Canada… Branta… 2014-03-04 08:15    30      45 US-MO      38.6
##  9    56 S173343… Canada… Branta… 2014-03-06 08:20     8      55 US-MO      38.6
## 10    57 S173450… Canada… Branta… 2014-03-07 08:20    38      55 US-MO      38.6
## # … with 1,662 more rows, 5 more variables: longitude <dbl>, count_tot <dbl>,
## #   month <dbl>, year <dbl>, SpeciesNum <int>, and abbreviated variable names
## #   ¹​common_name, ²​scientific_name, ³​duration, ⁴​location, ⁵​latitude

That year you observed 210 unique species of birds

##3. In which state did I most frequently observe Red-winged Blackbirds?

state_data <- filter(MBT_ebird, scientific_name == "Agelaius phoeniceus")

state_data2014 <- filter(state_data, year == 2014)

state_dataGrouped <- state_data2014 %>% group_by(location)

Missouri is the state you most frequently observed red-winged blackbirds

4. Filter observations for a duration between 5 and 200 minutes. Calculate the mean rate per checklist that I encounter species each year. Specifically, calculate the number of species in each checklist divided by duration and then take the mean for the year.

Mean_data <- filter(MBT_ebird, duration > 5, duration < 200)
mutated_Mean_data <- Mean_data %>% mutate(rate = n_distinct(common_name)/duration)

mutated_Mean_data2 <- mutated_Mean_data %>% group_by(year) %>%
                      mutate(year_mean = mean(rate))

View(mutated_Mean_data2)