filter_by_time: Filter (for Time-Series Data)

Description Usage Arguments Details References See Also Examples

View source: R/dplyr-filter_by_time.R

Description

The easiest way to filter time-based start/end ranges using shorthand timeseries notation. See filter_period() for applying filter expression by period (windows).

Usage

1
filter_by_time(.data, .date_var, .start_date = "start", .end_date = "end")

Arguments

.data

A tibble with a time-based column.

.date_var

A column containing date or date-time values to filter. If missing, attempts to auto-detect date column.

.start_date

The starting date for the filter sequence

.end_date

The ending date for the filter sequence

Details

Pure Time Series Filtering Flexibilty

The .start_date and .end_date parameters are designed with flexibility in mind.

Each side of the time_formula is specified as the character 'YYYY-MM-DD HH:MM:SS', but powerful shorthand is available. Some examples are:

Key Words: "start" and "end"

Use the keywords "start" and "end" as shorthand, instead of specifying the actual start and end values. Here are some examples:

Internal Calculations

All shorthand dates are expanded:

This means that the following examples are equivalent (assuming your index is a POSIXct):

References

See Also

Time-Based dplyr functions:

Examples

1
2
3
4
5
6
7
8
9
library(tidyverse)
library(tidyquant)
library(timetk)

# Filter values in January 1st through end of February, 2013
FANG %>%
    group_by(symbol) %>%
    filter_by_time(.start_date = "start", .end_date = "2013-02") %>%
    plot_time_series(date, adjusted, .facet_ncol = 2, .interactive = FALSE)

timetk documentation built on Jan. 19, 2021, 1:06 a.m.