Skip to contents

Counts the Time differences (epochs) per group (in a grouped dataset)

Usage

count_difftime(dataset, Datetime.colname = Datetime)

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.

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.

Value

a tibble with the number of occurences of each time difference per group

Examples

#get a dataset with irregular intervals
filepath <- system.file("extdata/sample_data_LYS.csv", package = "LightLogR")
dataset <- import$LYS(filepath)
#> 
#> Successfully read in 11'422 observations across 1 Ids from 1 LYS-file(s).
#> Timezone set is UTC.
#> 
#> First Observation: 2023-06-21 00:00:12
#> Last Observation: 2023-06-22 23:59:48
#> Timespan: 2 days
#> 
#> Observation intervals: 
#>   Id              interval.time     n pct    
#> 1 sample_data_LYS 15s           10015 87.689%
#> 2 sample_data_LYS 16s            1367 11.969%
#> 3 sample_data_LYS 17s              23 0.201% 
#> 4 sample_data_LYS 18s              16 0.140% 


#count_difftime returns the number of occurences of each time difference
#and is more comprehensive in terms of a summary than `gap_finder` or 
#`dominant_epoch`
count_difftime(dataset)
#> # A tibble: 4 × 3
#> # Groups:   Id [1]
#>   Id              difftime       n
#>   <fct>           <Duration> <int>
#> 1 sample_data_LYS 15s        10015
#> 2 sample_data_LYS 16s         1367
#> 3 sample_data_LYS 17s           23
#> 4 sample_data_LYS 18s           16
dominant_epoch(dataset)
#> # A tibble: 1 × 3
#>   Id              dominant.epoch group.indices
#>   <fct>           <Duration>             <int>
#> 1 sample_data_LYS 15s                        1
gap_finder(dataset)
#> Found 10758 gaps. 761 Datetimes fall into the regular sequence.

#irregular data can be regularized with `aggregate_Datetime`
dataset %>% aggregate_Datetime(unit = "15 secs") %>% count_difftime()
#> # A tibble: 2 × 3
#> # Groups:   Id [1]
#>   Id              difftime       n
#>   <fct>           <Duration> <int>
#> 1 sample_data_LYS 15s        11324
#> 2 sample_data_LYS 30s           97