ts.sum() | Teradata Package for R - ts.sum() - Teradata Package for R

Teradata® Package for R User Guide

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for R
Release Number
17.20
Published
March 2024
Language
English (United States)
Last Update
2024-04-09
dita:mapPath
efv1707506846369.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
nqx1518630623256
Product Category
Teradata Vantage

The aggregate function ts.sum() returns the sum of values in the column grouped by time.

Nulls are not included in the result computation.
Arguments:
  • value.expression: Specify the column for which sum is to be computed.

Use ts.sum(distinct(column_name)) to exclude duplicate rows while calculating sum.

Example 1: Calculate the sum of the values of the 'temperature' column of sequenced PTI table

  • Calculate the sum.
    > df_seq_sum <- df_seq_grp %>% summarise(sum_temp = ts.sum(temperature))
  • Print the results.
    > df_seq_sum %>% arrange(TIMECODE_RANGE, buoyid, sum_temp)
    # Source:     lazy query [?? x 4]
    # Database:   [Teradata 16.20.50.01] [Teradata Native Driver 17.0.0.2]
    #   [TDAPUSER@<hostname>/TDAPUSERDB]
    # Ordered by: TIMECODE_RANGE, buoyid, sum_temp
      TIMECODE_RANGE                                     `GROUP BY TIME(MINUTES(~ buoyid sum_temp
      <chr>                                              <int64>                   <int>    <int>
    1 2014-01-06 08:00:00.000000+00:00,2014-01-06 08:30~ 35345                         0      219
    2 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:30~ 35347                         1      447
    3 2014-01-06 10:00:00.000000+00:00,2014-01-06 10:30~ 35349                        44      539
    4 2014-01-06 10:30:00.000000+00:00,2014-01-06 11:00~ 35350                        22       23
    5 2014-01-06 10:30:00.000000+00:00,2014-01-06 11:00~ 35350                        44       86
    6 2014-01-06 21:00:00.000000+00:00,2014-01-06 21:30~ 35371                         2      243

Example 2: Calculate the sum of the values of the 'temperature' column of non-PTI table

  • Calculate the sum.
    > df_nonpti_sum <- df_nonpti %>% group_by_time(timebucket.duration = "10m", timecode.column = "TIMECODE") %>% summarise(sum_temp = ts.sum(temperature))
  • Print the results.
    > df_nonpti_sum %>% arrange(TIMECODE_RANGE, sum_temp)
    # Source:     lazy query [?? x 3]
    # Database:   [Teradata 16.20.50.01] [Teradata Native Driver 17.0.0.2]
    #   [TDAPUSER@<hostname>/TDAPUSERDB]
    # Ordered by: TIMECODE_RANGE, sum_temp
      TIMECODE_RANGE                                           `GROUP BY TIME(MINUTES(1~ sum_temp
      <chr>                                                    <int64>                      <int>
    1 2014-01-06 08:00:00.000000+00:00,2014-01-06 08:10:00.00~ 2314993                        109
    2 2014-01-06 08:10:00.000000+00:00,2014-01-06 08:20:00.00~ 2314994                        110
    3 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:10:00.00~ 2314999                        447
    4 2014-01-06 10:00:00.000000+00:00,2014-01-06 10:10:00.00~ 2315005                        496
    5 2014-01-06 10:10:00.000000+00:00,2014-01-06 10:20:00.00~ 2315006                         43
    6 2014-01-06 10:30:00.000000+00:00,2014-01-06 10:40:00.00~ 2315008                         43
    7 2014-01-06 10:50:00.000000+00:00,2014-01-06 11:00:00.00~ 2315010                         43
    8 2014-01-06 21:00:00.000000+00:00,2014-01-06 21:10:00.00~ 2315071                        243