View source: R/zz-deprecated-data-utils.R
cut_time | R Documentation |
where the periodicity of the time series is expressed as numbers of days, weeks, months quarters, or years.
cut_time(
timepoints,
full_seq = timepoints,
unit = attr(timepoints, "unit"),
day_zero = attr(timepoints, "day_zero"),
factor = FALSE,
...
)
timepoints |
a set of times (defined by count of periods from a zero day - see 'date_to_time()') |
full_seq |
a full sequence of allowable dates as created by 'full_seq_dates()'. Alternatively a vector of dates will some regular periodicity, that will be used as an input for 'full_seq_dates()', if missing this will be derived from the data itself. |
unit |
the unit of the timepoints in terms of "1 week" |
day_zero |
the origin of the timepoints |
factor |
return the result as an ordered factor with the date ranges as a label. if false this returns a date vector where the date is |
... |
if full_seq is not give, or a plain vector of dates, other options for 'full_seq_dates()' can be set here. E.g. ('fmt="%d/%m/%Y", period="1 week") |
a set of dates, representing the start (or end) of the period the date falls into, where the period is defined by 'full_seq' - which is usually defined by 'full_seq_dates()'
#dates = as.Date(c("2020-01-01","2020-02-01","2020-01-15","2020-02-03",NA))
#fs = full_seq_dates(dates, "2 days")
#dates - cut_date(dates, fs)
#cut_date(dates,fs,TRUE)
# A weekly set of dates:
# dates2 = Sys.Date() + floor(stats::runif(50,max=10))*7
#times2 = date_to_time(dates2)
# in this specific situation the final date is not truncated because the
# input data is seen as an exact match for the whole output period.
#cut_time(times2, fmt = "%d/%b", factor = TRUE)
# if the input dates don't line up with the output dates
# there may be incomplete coverage of the first and last category.
# where the cutting results in short periods. In this instance
# the first and last periods are truncated to prevent them
# being counted as complete when they are in fact potentially missing a few days worth of data:
#cut_time(times2, fmt = "%d/%b", factor = TRUE, period = "-2 weeks", anchor="sun")
#times2 - cut_time(times2, fmt = "%d/%b", factor = FALSE, period = "-2 weeks", anchor="sun")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.