R/mts_filterMeta.R
mts_filterMeta.Rd
A generalized metadata filter for mts 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 FALSE or
NA
are dropped.
If an empty mts object is passed in, it is immediately returned, allowing for multiple filtering steps to be piped together and only checking for an empty mts object at the end of the pipeline.
mts_filterMeta(mts, ...)
mts object.
Logical predicates defined in terms of the variables in
mts$meta
.
A subset of the incoming mts time series object.
(A list with meta
and data
dataframes.)
Filtering is done on variables in mts$meta
.
library(MazamaTimeSeries)
# Filter for all labels with "SCSH"
scap <-
example_mts %>%
mts_filterMeta(communityRegion == "El Monte")
dplyr::select(scap$meta, ID, label, longitude, latitude, communityRegion)
#> ID label longitude latitude communityRegion
#> 36fa039140645de8_2504 2504 SCEM_03 -118.0335 34.06491 El Monte
#> 173ff64a55da1183_2693 2693 SCEM_04 -118.0114 34.05451 El Monte
#> 055497925c615bbd_2452 2452 SCEM_05 -118.0023 34.07729 El Monte
#> 6db0b260ed58bea0_2713 2713 scem_06 -118.0313 34.07163 El Monte
#> 8d9ad84c05e66fcb_2496 2496 SCEM_07 -118.0717 34.08501 El Monte
head(scap$data)
#> datetime 36fa039140645de8_2504 173ff64a55da1183_2693
#> 1 2019-07-01 07:00:00 12.89900 12.01483
#> 2 2019-07-01 08:00:00 13.89150 12.37000
#> 3 2019-07-01 09:00:00 14.83433 12.48583
#> 4 2019-07-01 10:00:00 15.84750 13.00417
#> 5 2019-07-01 11:00:00 16.29417 14.23800
#> 6 2019-07-01 12:00:00 16.91367 15.00083
#> 055497925c615bbd_2452 6db0b260ed58bea0_2713 8d9ad84c05e66fcb_2496
#> 1 NA 11.94833 15.24183
#> 2 NA 13.12333 15.25800
#> 3 NA 14.48250 14.16783
#> 4 NA 14.91900 13.29867
#> 5 NA 15.56867 13.46133
#> 6 NA 16.07867 13.63450