A generalized data filter for sts objects to choose rows/cases where conditions are true. Multiple conditions are combined with & or separated by a comma. Only rows where the condition evaluates to TRUE are kept. Rows where the condition evaluates to NA are dropped.

If an empty sts object is passed in, it is immediately returned, allowing for multiple filtering steps to be piped together and only checking for an empty sts object at the end of the pipeline.

sts_filter(sts, ...)

Arguments

sts

sts object.

...

Logical predicates defined in terms of the variables in sts$data.

Value

A subset of the incoming sts time series object. (A list with meta and data dataframes.)

Note

Filtering is done on values in sts$data.

Examples


library(MazamaTimeSeries)

unhealthy <- sts_filter(example_sts, pm25_A > 55.5, pm25_B > 55.5)
head(unhealthy$data)
#> # A tibble: 6 × 19
#>   datetime            pm25_A pm25_B temperature humidity pressure pm1_atm_A
#>   <dttm>               <dbl>  <dbl>       <dbl>    <dbl>    <dbl>     <dbl>
#> 1 2018-08-03 01:30:00  111.   110.           74       47       NA      66.9
#> 2 2018-08-06 16:46:00   57.4   56.6          72       54       NA      43.0
#> 3 2018-08-14 06:52:00   56.2   59.6          70       57       NA      33.3
#> 4 2018-08-14 07:01:00   56.5   58.0          70       57       NA      33.0
#> 5 2018-08-14 07:04:00   56.6   59.2          70       57       NA      33.3
#> 6 2018-08-14 07:05:00   56.0   59.4          70       58       NA      33.0
#> # ℹ 12 more variables: pm25_atm_A <dbl>, pm10_atm_A <dbl>, pm1_atm_B <dbl>,
#> #   pm25_atm_B <dbl>, pm10_atm_B <dbl>, uptime <dbl>, rssi <dbl>, memory <dbl>,
#> #   adc0 <dbl>, bsec_iaq <dbl>, datetime_A <dttm>, datetime_B <dttm>