Extracting values based on multiple criteria

I have a long data set with about 400k rows, and I am trying to extracting values based on multiple criteria.

On each day of the year, checklists with unique Ids are used to capture species presence.

How can I create a column with values that describe how many checklists did Species Aa appear on for each day of the year?

Species ChecklistID DayofYear
Aa      xyz                 1
Bb      xyz                 1
Cc      xyz                 1
Aa      swa                 1
Bb      swa                 1
Ee      dew                 2
Aa      gre                 3
Cc      gre                 3
Ee      fgv                 4
Aa      hyt                 5

The output I am expecting would look like this:

DayofYear ChecklistsWithSpeciesAa
1                2
2                0
3                1
4                0
5                1

Thanks for your help!

More involved if showing 0 values for DayOfYear is a requirement

suppressPackageStartupMessages({library(dplyr)
                                library(readr)})

dat <- read.csv('/home/roc/Desktop/grist.csv')
dat %>% filter(Species == "Aa") %>%
        group_by(DayofYear) %>%
        count() %>%
        rename(ChecklistsWithSpeciesAa = n)
#> # A tibble: 3 x 2
#> # Groups:   DayofYear [3]
#>   DayofYear ChecklistsWithSpeciesAa
#>       <int>                   <int>
#> 1         1                       2
#> 2         3                       1
#> 3         5                       1

Created on 2020-09-15 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.