Extract a timemask from a dataframe for use in extract_with_timemask

extract_timemask(df, ...)

Arguments

df

A dataframe containing time and label_col columns.

...

Expressions that return a logical value, and are defined in terms of the variables in df. If multiple expressions are included, they are combined with the & operator. Only rows for which all conditions evaluate to TRUE are kept.

Value

a list with a tibble for intervals and the total ON duration.

See also

extract_with_timemask for using the timemask.

Examples


# Data-masking syntax similar to dplyr::filter
sample <- example_data$head_movement_data_0[[1]]
extract_timemask(sample, pos_x^2 + pos_y^2 + pos_z^2 > 15)
#> $total_on_duration
#> [1] 0
#> 
#> $intervals
#> # A tibble: 0 × 2
#> # ℹ 2 variables: start_time <dbl>, end_time <dbl>
#> 
#> attr(,"class")
#> [1] "timemask"

# Programmatic use with Data-masking looks like
column_name <- "pos_x"
value <- mean(sample[[column_name]])
extract_timemask(sample, .data[[column_name]] > value)
#> $total_on_duration
#> [1] 7.8865
#> 
#> $intervals
#> # A tibble: 6 × 2
#>   start_time end_time
#>        <dbl>    <dbl>
#> 1       641.     643.
#> 2       644.     644.
#> 3       647.     648.
#> 4       652.     653.
#> 5       656.     656.
#> 6       657.     660.
#> 
#> attr(,"class")
#> [1] "timemask"