View source: R/aggregatebydate.R
AggregateByDate | R Documentation |
Aggregates values by date. Calls tapply
.
AggregateByDate(x, by, dates, FUN = sum, ...)
x |
A vector containing the values to be aggregated, or, a 1D-array, or some other structure with dates in the first column |
by |
The period used in the conversion (e.g., "week", "year"). |
dates |
Either dates or characters that can be coerced to dates. Inferred from x if not suppled (e.g., the names of x). |
FUN |
The function to be applied, or NULL. In the case of functions like +, If FUN is NULL, tapply returns a vector which can be used to subscript the multi-way array tapply normally produces. |
... |
Optional arguments to |
A vector of aggregated values.
z <- rep(1, 54)
dts <- seq.Date(as.Date("2017/01/01"), by = "week", length.out = length(z))
AggregateByDate(z, dates = dts, by = "year")
z <- seq_along(dts)
names(z) <- dts
AggregateByDate(z, by = "year", FUN = mean)
data(presidents, package = "datasets")
origin <- paste0(start(presidents)[1], "-01-01")
df <- data.frame(dates = seq.Date(as.Date(0, origin), length.out = length(presidents),
by = "quarters"),
x = as.numeric(presidents))
AggregateByDate(df, by = "year", FUN = median, na.rm = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.