rowaggregate.DTSg: Aggregate values row-wise

rowaggregate.DTSgR Documentation

Aggregate values row-wise

Description

Applies one or more provided summary functions row-wise to selected columns of a DTSg object.

Usage

## S3 method for class 'DTSg'
rowaggregate(
  x,
  resultCols,
  fun,
  ...,
  cols = self$cols(class = "numeric"),
  clone = getOption("DTSgClone")
)

Arguments

x

A DTSg object (S3 method only).

resultCols

A character vector either of length one (names of fun are appended in the case one or more functions are provided) or the same length as fun specifying the column names for the return values of fun.

fun

A summary function, (named) list of summary functions or (named) character vector specifying summary functions applied row-wise to all the values of the specified cols. The return value(s) must be of length one. See corresponding section for further information.

...

Further arguments passed on to fun.

cols

A character vector specifying the columns to apply fun to. Another possibility is a character string containing either comma separated column names, for example, "x,y,z", or the start and end column separated by a colon, for example, "x:z".

clone

A logical specifying if the object shall be modified in place or if a deep clone (copy) shall be made beforehand.

Value

Returns a DTSg object.

Summary functions

Some examples for fun are as follows:

  • mean

  • list(min = min, max = max)

  • c(sd = "sd", var = "var")

See Also

cols, getOption

Examples

# new DTSg object
DT <- data.table::data.table(
  date = flow$date,
  flow1 = flow$flow - abs(rnorm(nrow(flow))),
  flow2 = flow$flow,
  flow3 = flow$flow + abs(rnorm(nrow(flow)))
)
x <- DTSg$new(values = DT)

# mean and standard deviation of multiple measurements per timestamp
## R6 method
x$rowaggregate(
  resultCols = "flow",
  fun = list(mean = mean, sd = sd)
)$print()

## 'raggregate()' is a "hidden" R6 alias for 'rowaggregate()'
x$raggregate(
  resultCols = "flow",
  fun = list(mean = mean, sd = sd)
)$print()

## S3 method
print(rowaggregate(
  x = x,
  resultCols = "flow",
  fun = list(mean = mean, sd = sd)
))


DTSg documentation built on Sept. 28, 2023, 1:06 a.m.