Skip to contents

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 the Datetime.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 a symbol. Needs to be part of the dataset.

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

Value

a data.frame object identical to dataset but with the added column of binned datetimes.

Examples

#compare Datetime and Datetime.rounded
sample.data.environment %>%
  cut_Datetime() %>%
  dplyr::slice_sample(n = 5)
#> # A tibble: 10 × 4
#> # Groups:   Id [2]
#>    Datetime            Datetime.rounded        MEDI Id         
#>    <dttm>              <dttm>                 <dbl> <chr>      
#>  1 2023-08-15 01:30:02 2023-08-15 03:00:00     0    Environment
#>  2 2023-08-19 09:34:02 2023-08-19 09:00:00 43415.   Environment
#>  3 2023-08-20 18:00:02 2023-08-20 18:00:00 31626.   Environment
#>  4 2023-08-17 23:00:32 2023-08-18 00:00:00     0    Environment
#>  5 2023-08-17 16:49:02 2023-08-17 18:00:00 50903.   Environment
#>  6 2023-08-18 23:19:31 2023-08-19 00:00:00     0    Participant
#>  7 2023-08-15 06:05:51 2023-08-15 06:00:00     0.64 Participant
#>  8 2023-08-15 12:31:21 2023-08-15 12:00:00  2514.   Participant
#>  9 2023-08-15 14:02:01 2023-08-15 15:00:00   213.   Participant
#> 10 2023-08-20 17:20:01 2023-08-20 18:00:00   245.   Participant