condense_period: Convert the Period to a Lower Periodicity (e.g. Go from Daily...

Description Usage Arguments Value See Also Examples

View source: R/dplyr-condense_period.R

Description

Convert a data.frame object from daily to monthly, from minute data to hourly, and more. This allows the user to easily aggregate data to a less granular level by taking the value from either the beginning or end of the period.

Usage

1
condense_period(.data, .date_var, .period = "1 day", .side = c("start", "end"))

Arguments

.data

A tbl object or data.frame

.date_var

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

.period

A period to condense the time series to. Time units are condensed using lubridate::floor_date() or lubridate::ceiling_date().

The value can be:

  • second

  • minute

  • hour

  • day

  • week

  • month

  • bimonth

  • quarter

  • season

  • halfyear

  • year

Arbitrary unique English abbreviations as in the lubridate::period() constructor are allowed:

  • "1 year"

  • "2 months"

  • "30 seconds"

.side

One of "start" or "end". Determines if the first observation in the period should be returned or the last.

Value

A tibble or data.frame

See Also

Time-Based dplyr functions:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Libraries
library(timetk)
library(dplyr)

# First value in each month
m4_daily %>%
    group_by(id) %>%
    condense_period(.period = "1 month")

# Last value in each month
m4_daily %>%
    group_by(id) %>%
    condense_period(.period = "1 month", .side = "end")

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