splitByDate | R Documentation |
This function partitions a data frame up into different time segments. It
produces a new column called controlled by name
that can be used in many
openair
functions. Note that there must be one more labels
than there are
dates
.
splitByDate(
mydata,
dates = "1/1/2003",
labels = c("before", "after"),
name = "split.by",
format = c("%d/%m/%Y", "%Y/%m/%d", "%d/%m/%Y %H:%M:%S",
"%Y/%m/%d %H:%M:%S")
)
mydata |
A data frame containing a |
dates |
A date or dates to split data by. Can be passed as R date(time)
objects or as characters. If passed as a character, |
labels |
Labels for each time partition. Should always be one more
|
name |
The name to give the new column to identify the periods split.
Defaults to |
format |
When |
David Carslaw
# split data up into "before" and "after"
mydata <- splitByDate(mydata,
dates = "1/04/2000",
labels = c("before", "after")
)
# split data into 3 partitions
mydata <- splitByDate(mydata,
dates = c("1/1/2000", "1/3/2003"),
labels = c("before", "during", "after")
)
# if you have modelled data - could split into modelled and measured by the
# break date
dummy <- data.frame(
date = Sys.Date() + (-5:5),
nox = 100 + seq(-50, 50, 10)
)
splitByDate(dummy,
dates = Sys.Date(),
labels = c("measured", "modelled"),
name = "data_type"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.