Round down movement dates, and/or summarise data by time unit
round_dates.Rd
round_dates()
rounds movement dates in a movenet-format movement
tibble, down to the first day of the specified time unit. It optionally
summarises movement data with the same origin and destination by this time
unit. By default, this involves summation of weights, but alternative or
additional summary functions can be provided through ...
.
Usage
round_dates(
data,
unit,
week_start = getOption("lubridate.week.start", 7),
sum_weight = TRUE,
...
)
Arguments
- data
A movenet-format movement tibble.
- unit
A character string specifying a time unit or a multiple of a unit for movement dates to be rounded down to. Valid base units are
day
,week
,month
,bimonth
,quarter
,season
,halfyear
andyear
. Arbitrary unique English abbreviations as in thelubridate::period()
constructor are allowed. Rounding to multiples of units (except weeks) is supported.- week_start
Week start day, only relevant for rounding down dates and/ or aggregating data by week. Default is the value of the
lubridate.week.start
option, or 7 (Sunday) if this option is not set. Full or abbreviated names of the days of the week can be in English or as provided by the current locale.- sum_weight
If this is
TRUE
(the default), weights are summed overunit
, for all rows with the same origin and destination. The name of the weight column will remain the same.- ...
data-masking
Additional or alternative summary function(s), of the form name = value, to pass on todplyr::summarise()
. Any summary functions will be applied todata
, grouped by origin, destination, and rounded-down date. The specified name will be the column name in the resulting tibble. The value can be:A vector of length 1, e.g.
min(x)
,n()
, orsum(is.na(y))
.A vector of length n, e.g.
quantile()
.A tibble, to add multiple columns from a single expression.
Value
A movement tibble like data
, but with rounded-down movement dates.
If sum_weight
is TRUE
or any summary functions are provided through
...
, the returned tibble contains data summarised by origin,
destination, and unit
, and may thus have a decreased length compared to
data
.
Columns for which a summary function is not provided, are dropped from the resulting tibble.
Details
Requires that an appropriate movement config file is loaded, to correctly
identify origin (from
), destination (to
), date
and weight
columns in
data
.
Movement dates are rounded to the first day of the rounding unit specified in
unit
.
If sum_weight
is TRUE
, weights are summed over all rows in data
with
the same origin, destination, and rounded-down date. The summed weight column
is temporarily renamed, so that any additional weight-dependent summary
functions passed through ...
use the original weights rather than the sums.
If any summary functions are provided through ...
, the specified data are
summarised accordingly, over all rows in data
with the same origin,
destination, and rounded-down date. Be careful when using' existing names:
the corresponding columns will be immediately updated with the new data and
this can affect subsequent operations referring to this name.
Columns for which a summary function is not provided, are dropped from the resulting tibble.
See also
lubridate::floor_date()
, dplyr::summarise()
which this function
wraps.