cut_timeseries_periodic: Cut a tibble with a datetime column

View source: R/cutfuns.R

cut_timeseries_periodicR Documentation

Cut a tibble with a datetime column

Description

Appends new factor variables as columns to the dataset, for further use with e.g. summary_periodic() in order to calculate summary stats for starttime of the day, date, weekday, weekend, week, month, season, daylight.

Usage

cut_timeseries_periodic(
  data,
  x = "starttime",
  include_daylight = TRUE,
  coords = c(lat = 47.36667, lon = 8.55)
)

Arguments

data

tibble containing a column starttime of type POSIXct with a timezone

x

symbolic reference to date time column used for cutting

include_daylight

boolean indicating to calculate daylight for each starttime. Disable to improve perfomance.

coords

a named vector of the location in WGS84 coordinates for the daylight factoring. suncalc::getSunlightTimes() is used to calculate sunrise, sunset times. Default: c(lat = 47.36667, lon = 8.55) => Zuerich, Switzerland

Value

a tibble with cut data; cut-factors comprise various (time-)periodic new columns:

  • starttime_of_day: cut_time_of_day(x)

  • date: lubridate::as_date(x) to preserve time zone don't use base::as.Date()

  • weekday: lubridate::wday(x, label = TRUE, week_start = 1) locale Abbreviations (Mon, Tue, Wed, Thu, Fri, Sat, Sun)

  • weekend: cut_weekend(x) => Wochentag, Wochenende (use cut_weekend() manually or recode factor to change levels)

  • week: lubridate::week(x)

  • month: lubridate::month(x, label = TRUE) locale Abbreviations (Jan, Feb, Mar, ...)

  • season: cut_season(x) => DJF, MAM, JJA, SON (use cut_season() manually or recode factor to change levels)

  • daylight: cut_daylight(x, coords) => Tag, Nacht (use cut_daylight() manually or recode factor to change levels)

Examples

fn <- rOstluft.data::f("Zch_Stampfenbachstrasse_h1_2013_Jan.csv")
data <- rOstluft::read_airmo_csv(fn)

data <- cut_timeseries_periodic(data)
tibble::glimpse(data)

# recoding a factor
data <- dplyr::mutate(data,
  daylight = dplyr::recode(daylight, Nacht = "night", Tag = "day"),
)
tibble::glimpse(data)


Ostluft/rOstluft.plot documentation built on Jan. 26, 2025, 1:05 a.m.