filter.epi_archive: 'dplyr::filter' for 'epi_archive's

View source: R/methods-epi_archive.R

filter.epi_archiveR Documentation

dplyr::filter for epi_archives

Description

dplyr::filter for epi_archives

Usage

## S3 method for class 'epi_archive'
filter(.data, ..., .by = NULL, .format_aware = FALSE)

Arguments

.data

an epi_archive

...

as in dplyr::filter; using the version column is not allowed unless you use .format_aware = TRUE; see details.

.by

as in dplyr::filter

.format_aware

optional, TRUE or FALSE; default FALSE. See details.

Details

By default, using the version column or measurement columns is disabled as it's easy to get unexpected results. See if either epix_as_of or epix_slide works for any version selection you have in mind: for version selection, see the version or .versions args, respectively; for measurement column-based filtering, try filtering after epix_as_of or inside the .f in epix_slide(). If they don't cover your use case, then you can set .format_aware = TRUE to enable usage of these columns, but be careful to:

  • Factor in that .data$DT may have been converted into a compact format based on diffing consecutive versions, and the last version of each observation in .data$DT will always be carried forward to future versions⁠; see details of [⁠as_epi_archive'].

  • Set clobberable_versions_start and versions_end of the result appropriately after the filter call. They will be initialized with the same values as in .data.

dplyr::filter also has an optional argument .preserve, which should not have an impact on (ungrouped) epi_archives, and grouped_epi_archives do not currently support dplyr::filter.

Examples


# Filter to one location and a particular time range:
archive_cases_dv_subset %>%
  filter(geo_value == "fl", time_value >= as.Date("2020-10-01"))

# Convert to weekly by taking the Saturday data for each week, so that
# `case_rate_7d_av` represents a Sun--Sat average:
archive_cases_dv_subset %>%
  filter(as.POSIXlt(time_value)$wday == 6L)

# Filtering involving the `version` column or measurement columns requires
# extra care. See epix_as_of and epix_slide instead for some common
# operations. One semi-common operation that ends up being fairly simple is
# treating observations as finalized after some amount of time, and ignoring
# any revisions that were made after that point:
archive_cases_dv_subset %>%
  filter(
    version <= time_value + as.difftime(60, units = "days"),
    .format_aware = TRUE
  )


cmu-delphi/epitools documentation built on April 17, 2025, 3:33 a.m.