Subsets a MazamaSingleTimeseries object by datetime. This function allows for sub-day filtering as opposed to sts_filterDate() which always filters to day-boundaries.

Datetimes can be anything that is understood by MazamaCoreUtils::parseDatetime(). For non-POSIXct values, the recommended format is "YYYY-mm-dd HH:MM:SS".

Timezone determination precedence assumes that if you are passing in POSIXct values then you know what you are doing.

  1. get timezone from startdate if it is POSIXct

  2. use passed in timezone

  3. get timezone from sts

sts_filterDatetime(
  sts = NULL,
  startdate = NULL,
  enddate = NULL,
  timezone = NULL,
  unit = "sec",
  ceilingStart = FALSE,
  ceilingEnd = FALSE,
  includeEnd = FALSE
)

Arguments

sts

MazamaSingleTimeseries sts object.

startdate

Desired start datetime (ISO 8601).

enddate

Desired end datetime (ISO 8601).

timezone

Olson timezone used to interpret dates.

unit

Units used to determine time at end-of-day.

ceilingStart

Logical instruction to apply ceiling_date to the startdate rather than floor_date

ceilingEnd

Logical instruction to apply ceiling_date to the enddate rather than floor_date

includeEnd

Logical specifying that records associated with enddate should be included.

Value

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

Note

The returned sts object will contain data running from the beginning of startdate until the beginning of enddate -- i.e. no values associated with enddate will be returned. To include enddate you can specify includeEnd = TRUE.

Examples

library(MazamaTimeSeries)

example_sts %>%
  sts_filterDatetime(
    startdate = "2018-08-08 06:00:00",
    enddate = "2018-08-14 18:00:00"
  ) %>%
  sts_extractData() %>%
  head()
#> # 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-08 13:00:00   11.4   11.1          72       49       NA      8.85
#> 2 2018-08-08 13:01:00   12.3   10.6          72       49       NA      9.41
#> 3 2018-08-08 13:02:00   11.7   NA            72       49       NA      9   
#> 4 2018-08-08 13:03:00   NA     11.6          NA       NA       NA     NA   
#> 5 2018-08-08 13:04:00   12.6   11.2          72       50       NA      9.57
#> 6 2018-08-08 13:05:00   12.8   12            72       51       NA      9.31
#> # ℹ 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>