This workbook is a study of using lubridate to count testing cases by week. My initial testing based on a chapter from R for Data Science had the counts by week ending on Sunday when I thought that was the beginning of the week. I think this is something about the ceiling_date. I was able to subtract 1 from that ceiling to give me the Saturday date. This checks that logic to make sure I’m not counting the wrong days.
This is the way to formulate the count by week:
count(week = ceiling_date(lab_date, "week") - 1)
library(tidyverse)
library(lubridate)
riverside <- read_rds("data-processed/riverside.rds")
riverside %>% glimpse()
## Rows: 1,967,201
## Columns: 4
## $ lab_date <date> 2020-01-04, 2020-01-04, 2020-01-04, 2020-01-04, 2020-01-0…
## $ place <chr> "TEMECULA", "MURRIETA", "INDIO", "INDIO", "HEMET", "RIVERS…
## $ zipcode <chr> "92591", "92563", "92203", "92203", "92543", "92503", "928…
## $ lab_result <chr> "Negative", "Negative", "Negative", "Positive", "Negative"…
Building test data for feb 2020
test_feb <- riverside %>%
filter(month(lab_date) == 2)
View of Feb data
test_feb
This shows counts by data at the beginning of the week.
test_feb %>%
count(week = floor_date(lab_date, "week"))
This shows the date of the end of the week. The ceiling_date
for week is the Sunday of the next week, so I’m subtracting one day to get the Saturday. At least that is how it is working for Feb.
test_feb %>%
count(week = ceiling_date(lab_date, "week")-1)
test_mar_ps <- riverside %>%
filter(
lab_date >= "2020-03-1",
lab_date <= "2020-03-15",
place == "PALM SPRINGS"
)
test_mar_ps
test_mar_ps %>%
count(week = ceiling_date(lab_date, "week")-1)
tests the week enxing March 14.
test_mar_ps %>%
filter(
lab_date >= "2020-03-08",
lab_date <= "2020-03-14"
)