cut_Datetime
is a wrapper around lubridate::round_date()
(and friends)
combined with dplyr::mutate()
, to create a new column in a light logger
dataset with a specified binsize. This can be "3 hours"
, "15 secs"
, or
"0.5 days"
. It is a useful step between a dataset and a visualization or
summary step.
Usage
cut_Datetime(
dataset,
unit = "3 hours",
type = c("round", "floor", "ceiling"),
Datetime.colname = Datetime,
New.colname = Datetime.rounded,
group_by = FALSE,
...
)
Arguments
- dataset
A light logger dataset. Expects a
dataframe
. If not imported by LightLogR, take care to choose a sensible variable for theDatetime.colname
.- unit
Unit of binning. See
lubridate::round_date()
for examples. The default is"3 hours"
.- type
One of
"round"
(the default),"ceiling"
or"floor"
. Setting chooses the relevant function from lubridate.- Datetime.colname
column name that contains the datetime. Defaults to
"Datetime"
which is automatically correct for data imported with LightLogR. Expects asymbol
. Needs to be part of thedataset
. Must be of typePOSIXct
.- New.colname
Column name for the added column in the
dataset
.- group_by
Should the data be grouped by the new column? Defaults to
FALSE
- ...
Parameter handed over to
lubridate::round_date()
and siblings
Examples
#compare Datetime and Datetime.rounded
sample.data.environment %>%
cut_Datetime() %>%
dplyr::slice_sample(n = 5)
#> # A tibble: 10 × 4
#> # Groups: Id [2]
#> Id Datetime Datetime.rounded MEDI
#> <fct> <dttm> <dttm> <dbl>
#> 1 Environment 2023-08-29 01:30:08 2023-08-29 03:00:00 0
#> 2 Environment 2023-09-02 09:34:08 2023-09-02 09:00:00 50373.
#> 3 Environment 2023-09-03 18:00:08 2023-09-03 18:00:00 16271.
#> 4 Environment 2023-08-31 23:00:38 2023-09-01 00:00:00 0
#> 5 Environment 2023-08-31 16:49:08 2023-08-31 18:00:00 31367.
#> 6 Participant 2023-09-01 23:19:34 2023-09-02 00:00:00 0
#> 7 Participant 2023-08-29 06:05:54 2023-08-29 06:00:00 0
#> 8 Participant 2023-08-29 12:31:24 2023-08-29 12:00:00 45.0
#> 9 Participant 2023-08-29 14:02:04 2023-08-29 15:00:00 17.6
#> 10 Participant 2023-09-03 17:20:04 2023-09-03 18:00:00 4027.