Hello and welcome to Stack.
Your question is likely being downvoted for sharing an image, rather than code, which is easier for answering people to use: How to make a great R reproducible example
Using dplyr
and lubridate
, this is how I would do what you are looking for:
library(dplyr)
library(lubridate)
#Setting seed to be reproducible
set.seed(123)
#Creating a example dataframe toutilize
temp <- data.frame("Student_ID" = LETTERS,
"Period" = c(rep("2022", 9),
rep("2023", 9),
rep("2024", 8)
),
"Received_Date" = c(
sample(seq(as.Date('2022/01/01'), as.Date('2022/12/31'), by="day"), 9),
sample(seq(as.Date('2023/01/01'), as.Date('2023/12/31'), by="day"), 9),
sample(seq(as.Date('2024/01/01'), as.Date('2024/12/31'), by="day"), 8)
)
)
temp %>%
#Grouping by the period that we want the summary for
#For all records in that period, how many of the received dates are before July (month 7)
#And how many are in July or after
group_by(Period) %>%
summarise("Before_July1" = sum(month(Received_Date) < 7),
"After_July1" = sum(month(Received_Date) >= 7),
.groups = "drop")
Result:
Period Before_July1 After_July1
<fct> <int> <int>
1 2022 3 6
2 2023 4 5
3 2024 5 3