View source: R/extract_states.R
| add_states | R Documentation |
add_states() brings states to a time series dataset. It uses the
States.dataset to add states to the dataset. The States.dataset must at
least contain the same variables as the dataset grouping, as well as a
start and end time. Beware if both datasets operate on different time zones
and consider to set force.tz = TRUE.
add_states(
dataset,
States.dataset,
Datetime.colname = Datetime,
start.colname = start,
end.colname = end,
force.tz = FALSE,
leave.out = c("duration", "epoch")
)
dataset |
A light logger dataset. Needs to be a dataframe. |
States.dataset |
A light logger dataset. Needs to be a dataframe. This
dataset must contain the same variables as the |
Datetime.colname |
The column that contains the datetime. Needs to be a
|
start.colname, end.colname |
The columns that contain the start and end
time. Need to be |
force.tz |
If |
leave.out |
A character vector of columns that should not be carried
over to the |
Beware if columns in the dataset and States.dataset have the same name
(other then grouping variables). The underlying function,
dplyr::left_join() will mark the columns in the dataset with a suffix
.x, and in the States.dataset with a suffix .y.
a modified dataset with the states added. The states are added as
new columns to the dataset. The columns are named after the columns in
the States.dataset, except for the start and end times, which are
removed.
states <-
sample.data.environment |>
filter_Date(length = "1 day") |>
extract_states(Daylight, MEDI > 1000)
states |> head(2)
#add states to a dataset and plot them - as we only looked for states on the
# first day (see above), only the first day will show up in the plot
sample.data.environment |>
filter_Date(length = "2 day") |>
add_states(states) |>
gg_days() |>
gg_state(Daylight)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.