Skip to contents

Function will group the data and estimate the frequency of the time stamps, returning 'year', 'quarter', 'month', 'week' or 'day'. You can use it on raw or aggregated data frames

Usage

get_frequency(df, date_field = NULL)

Arguments

df

data.frame() or tibble() Data frame of tibble, can be aggregated or raw

date_field

Date field to be analyzed, by default the first date-like column will be used

Value

frequency - "quarter", "month", "week" or "day"

Examples

sales %>%
  dplyr::mutate(Date = lubridate::floor_date(Date, unit = "month")) %>%
  get_frequency()
#> [1] "month"

sales %>%
  dplyr::mutate(Date = lubridate::floor_date(Date, unit = "week")) %>%
  get_frequency()
#> [1] "week"

sales %>%
  dplyr::mutate(Date = lubridate::floor_date(Date, unit = "quarter")) %>%
  dplyr::group_by(Region, Date) %>%
  dplyr::summarise(Sales = sum(Sales, na.rm = TRUE)) %>%
  get_frequency()
#> [1] "quarter"

get_frequency(sales)
#> [1] "day"