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

# S3 method for 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:

See also

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()
#> Values:
#>        .dateTime     flow1  flow2     flow3 flow.mean   flow.sd
#>           <POSc>     <num>  <num>     <num>     <num>     <num>
#>    1: 2007-01-01  9.477941  9.540 10.185332  9.734424 0.3917286
#>    2: 2007-01-02  9.189006  9.285 10.137547  9.537185 0.5221401
#>    3: 2007-01-03  8.297175  8.940 10.170939  9.136038 0.9521399
#>    4: 2007-01-04  8.360077  8.745 10.173239  9.092772 0.9552999
#>    5: 2007-01-05  7.940256  8.490  8.987618  8.472624 0.5238971
#>   ---                                                          
#> 2188: 2012-12-27 25.803124 26.685 27.111856 26.533327 0.6674195
#> 2189: 2012-12-28 25.596173 28.050 28.094173 27.246782 1.4296396
#> 2190: 2012-12-29 23.152640 23.580 24.840379 23.857673 0.8774635
#> 2191: 2012-12-30 17.492049 18.840 19.888665 18.740238 1.2014186
#> 2192: 2012-12-31 17.090295 17.250 17.991826 17.444040 0.4810703
#> 
#> Aggregated:     FALSE
#> Regular:        TRUE
#> Periodicity:    Time difference of 1 days
#> Missing values: explicit
#> Time zone:      UTC
#> Timestamps:     2192

## 'raggregate()' is a "hidden" R6 alias for 'rowaggregate()'
x$raggregate(
  resultCols = "flow",
  fun = list(mean = mean, sd = sd)
)$print()
#> Values:
#>        .dateTime     flow1  flow2     flow3 flow.mean   flow.sd
#>           <POSc>     <num>  <num>     <num>     <num>     <num>
#>    1: 2007-01-01  9.477941  9.540 10.185332  9.734424 0.3917286
#>    2: 2007-01-02  9.189006  9.285 10.137547  9.537185 0.5221401
#>    3: 2007-01-03  8.297175  8.940 10.170939  9.136038 0.9521399
#>    4: 2007-01-04  8.360077  8.745 10.173239  9.092772 0.9552999
#>    5: 2007-01-05  7.940256  8.490  8.987618  8.472624 0.5238971
#>   ---                                                          
#> 2188: 2012-12-27 25.803124 26.685 27.111856 26.533327 0.6674195
#> 2189: 2012-12-28 25.596173 28.050 28.094173 27.246782 1.4296396
#> 2190: 2012-12-29 23.152640 23.580 24.840379 23.857673 0.8774635
#> 2191: 2012-12-30 17.492049 18.840 19.888665 18.740238 1.2014186
#> 2192: 2012-12-31 17.090295 17.250 17.991826 17.444040 0.4810703
#> 
#> Aggregated:     FALSE
#> Regular:        TRUE
#> Periodicity:    Time difference of 1 days
#> Missing values: explicit
#> Time zone:      UTC
#> Timestamps:     2192

## S3 method
print(rowaggregate(
  x = x,
  resultCols = "flow",
  fun = list(mean = mean, sd = sd)
))
#> Values:
#>        .dateTime     flow1  flow2     flow3 flow.mean   flow.sd
#>           <POSc>     <num>  <num>     <num>     <num>     <num>
#>    1: 2007-01-01  9.477941  9.540 10.185332  9.734424 0.3917286
#>    2: 2007-01-02  9.189006  9.285 10.137547  9.537185 0.5221401
#>    3: 2007-01-03  8.297175  8.940 10.170939  9.136038 0.9521399
#>    4: 2007-01-04  8.360077  8.745 10.173239  9.092772 0.9552999
#>    5: 2007-01-05  7.940256  8.490  8.987618  8.472624 0.5238971
#>   ---                                                          
#> 2188: 2012-12-27 25.803124 26.685 27.111856 26.533327 0.6674195
#> 2189: 2012-12-28 25.596173 28.050 28.094173 27.246782 1.4296396
#> 2190: 2012-12-29 23.152640 23.580 24.840379 23.857673 0.8774635
#> 2191: 2012-12-30 17.492049 18.840 19.888665 18.740238 1.2014186
#> 2192: 2012-12-31 17.090295 17.250 17.991826 17.444040 0.4810703
#> 
#> Aggregated:     FALSE
#> Regular:        TRUE
#> Periodicity:    Time difference of 1 days
#> Missing values: explicit
#> Time zone:      UTC
#> Timestamps:     2192