pad_cust: Pad with a custom spanning

View source: R/pad_cust.R

pad_custR Documentation

Pad with a custom spanning

Description

Pad the datetime variable after thicken_cust is applied, using the same spanning.

Usage

pad_cust(x, spanned, by = NULL, group = NULL, drop_last_spanned = TRUE)

Arguments

x

A data frame containing at least one datetime variable of class Date, POSIXct or POSIXlt.

spanned

A datetime vector to which the the datetime variable in x should be mapped. See subset_span for quickly spanning unequally spaced variables.

by

Only needs to be specified when x contains multiple variables of class Date, POSIXct or POSIXlt.

group

Optional character vector that specifies the grouping variable(s). Padding will take place within the different group values.

drop_last_spanned

Logical, indicating whether to drop the last value from spanned. The spanned is typically around the datetime variable. This would create an empty last record when padding. Setting to TRUE will drop the last value in spanned and will not create an empty last record in this situation.

Value

The data frame x with the datetime column padded.

Examples

library(dplyr)
# analysis of traffic accidents in traffic jam hours and other hours.
accidents <- emergency %>% filter(title == "Traffic: VEHICLE ACCIDENT -")
spanning <- span_time("20151210 16", "20161017 17", tz = "EST") %>%
  subset_span(list(hour = c(6, 9, 16, 19)))
thicken_cust(accidents, spanning, "period") %>%
  count(period) %>%
  pad_cust(spanning)

padr documentation built on Nov. 23, 2022, 5:06 p.m.