time_expandv {timeplyr} | R Documentation |
Vector date and datetime functions
Description
These are atomic vector-based functions of the tidy equivalents which all have a "v" suffix to denote this. These are more geared towards programmers and allow for working with date and datetime vectors.
Usage
time_expandv(
x,
time_by = NULL,
from = NULL,
to = NULL,
g = NULL,
use.g.names = TRUE,
time_type = getOption("timeplyr.time_type", "auto"),
time_floor = FALSE,
week_start = getOption("lubridate.week.start", 1),
roll_month = getOption("timeplyr.roll_month", "preday"),
roll_dst = getOption("timeplyr.roll_dst", "NA")
)
time_span(
x,
time_by = NULL,
from = NULL,
to = NULL,
g = NULL,
use.g.names = TRUE,
time_type = getOption("timeplyr.time_type", "auto"),
time_floor = FALSE,
week_start = getOption("lubridate.week.start", 1),
roll_month = getOption("timeplyr.roll_month", "preday"),
roll_dst = getOption("timeplyr.roll_dst", "NA")
)
time_completev(
x,
time_by = NULL,
from = NULL,
to = NULL,
sort = TRUE,
time_type = getOption("timeplyr.time_type", "auto"),
time_floor = FALSE,
week_start = getOption("lubridate.week.start", 1),
roll_month = getOption("timeplyr.roll_month", "preday"),
roll_dst = getOption("timeplyr.roll_dst", "NA")
)
time_summarisev(
x,
time_by = NULL,
from = NULL,
to = NULL,
sort = FALSE,
unique = FALSE,
time_type = getOption("timeplyr.time_type", "auto"),
time_floor = FALSE,
week_start = getOption("lubridate.week.start", 1),
roll_month = getOption("timeplyr.roll_month", "preday"),
roll_dst = getOption("timeplyr.roll_dst", "NA"),
as_interval = getOption("timeplyr.use_intervals", FALSE)
)
time_countv(
x,
time_by = NULL,
from = NULL,
to = NULL,
sort = TRUE,
unique = TRUE,
complete = FALSE,
time_type = getOption("timeplyr.time_type", "auto"),
time_floor = FALSE,
week_start = getOption("lubridate.week.start", 1),
roll_month = getOption("timeplyr.roll_month", "preday"),
roll_dst = getOption("timeplyr.roll_dst", "NA"),
as_interval = getOption("timeplyr.use_intervals", FALSE)
)
time_span_size(
x,
time_by = NULL,
from = NULL,
to = NULL,
g = NULL,
use.g.names = TRUE,
time_type = getOption("timeplyr.time_type", "auto"),
time_floor = FALSE,
week_start = getOption("lubridate.week.start", 1)
)
Arguments
x |
Time variable. |
time_by |
Time unit.
|
from |
Time series start date. |
to |
Time series end date. |
g |
Grouping object passed directly to |
use.g.names |
Should the result include group names?
Default is |
time_type |
If "auto", |
time_floor |
Should |
week_start |
day on which week starts following ISO conventions - 1
means Monday (default), 7 means Sunday.
This is only used when |
roll_month |
Control how impossible dates are handled when
month or year arithmetic is involved.
Options are "preday", "boundary", "postday", "full" and "NA".
See |
roll_dst |
See |
sort |
Should the output be sorted? Default is |
unique |
Should the result be unique or match the length of the vector?
Default is |
as_interval |
Should result be a |
complete |
Logical. If |
Value
Vectors (typically the same class as x
) of varying lengths depending
on the arguments supplied.
time_countv()
returns a tibble
.
Examples
library(timeplyr)
library(dplyr)
library(lubridate)
library(nycflights13)
x <- unique(flights$time_hour)
# Number of missing hours
time_num_gaps(x)
# Same as above
time_span_size(x) - length(unique(x))
# Time sequence that spans the data
length(time_span(x)) # Automatically detects hour granularity
time_span(x, time_by = "month")
time_span(x, time_by = list("quarters" = 1),
to = today(),
# Floor start of sequence to nearest month
time_floor = TRUE)
# Complete missing gaps in time using time_completev
y <- time_completev(x, time_by = "hour")
identical(y[!y %in% x], time_gaps(x))
# Summarise time using time_summarisev
time_summarisev(y, time_by = "quarter")
time_summarisev(y, time_by = "quarter", unique = TRUE)
flights %>%
fcount(quarter = time_summarisev(time_hour, "quarter"))
# Alternatively
time_countv(flights$time_hour, time_by = "quarter")
# If you want the above as an atomic vector just use tibble::deframe