View source: R/aggregate_index.R
aggregate_index | R Documentation |
tsibble
aggregate_index()
allows you to aggregate the index of a
tsibble
object by applying a specific function to its
measured variables.
aggregate_index(data, unit, fun = NULL, week_start = 1)
data |
A |
unit |
A string indicating at which time unit the index must be
aggregated. Valid values are: |
fun |
(optional) The |
week_start |
(optional) an integer number indicating the day on which
the week starts ( |
aggregate_index()
was created to easily regularize
tsibble
objects. If you need more control while doing
this operation, check the index_by()
function
provided by the tsibble
package.
If fun == NULL
, aggregate_index()
will use the following function to
transform each measured variable:
function(x) { checkmate::assert_atomic_vector(x) if (is.numeric(x) && !all(nchar(x) == 1, na.rm = TRUE)) { mean(x, na.rm = TRUE) } else { y <- x[which(!is.na(x))] unique <- unique(y) unique[which.max(tabulate(match(y, unique)))] } }
This function average values for numeric variables and assigning the most
frequent value (mode) for single integer or other type of variables. If no
mode can be found, the function will return the first value of x
.
A tsibble
object.
Other utility functions:
find_epoch()
,
raw_data()
,
read_acttrust()
,
write_acttrust()
acttrust
aggregate_index(acttrust, unit = "hour")
aggregate_index(acttrust, unit = "day")
aggregate_index(acttrust, unit = "week")
aggregate_index(acttrust, unit = "month")
aggregate_index(acttrust, unit = "quarter")
aggregate_index(acttrust, unit = "year")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.