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

Teradata® Package for R User Guide

Product
Teradata Package for R
Release Number
17.00
Published
July 2021
Language
English (United States)
Last Update
2023-08-08
dita:mapPath
yih1585763700215.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
B700-4005
Product Category
Teradata Vantage

The aggregate function ts.max() returns the maximum value in the column grouped by time.

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

Use ts.max(distinct(column_name)) to exclude duplicate rows while calculating maximum value.

Example 1: Calculate the maximum value in the 'temperature' column of sequenced PTI table

  • Calculate the maximum value.
    > df_seq_max <- df_seq_grp %>% summarise(max_temp = ts.max(temperature))
  • Print the results.
    > df_seq_max %>% arrange(TIMECODE_RANGE, buoyid, max_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, max_temp
      TIMECODE_RANGE                                     `GROUP BY TIME(MINUTES(~ buoyid max_temp
      <chr>                                              <int64>                   <int>    <int>
    1 2014-01-06 08:00:00.000000+00:00,2014-01-06 08:30~ 35345                         0      100
    2 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:30~ 35347                         1       79
    3 2014-01-06 10:00:00.000000+00:00,2014-01-06 10:30~ 35349                        44       56
    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       43
    6 2014-01-06 21:00:00.000000+00:00,2014-01-06 21:30~ 35371                         2       82

Example 2: Calculate the maximum value in the 'temperature' column of non-PTI table

  • Calculate the maximum value.
    > df_nonpti_max <- df_nonpti %>% group_by_time(timebucket.duration = "10m", timecode.column = "TIMECODE") %>% summarise(max_temp = ts.max(temperature))
  • Print the results.
    > df_nonpti_max %>% arrange(TIMECODE_RANGE, max_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, max_temp
      TIMECODE_RANGE                                           `GROUP BY TIME(MINUTES(1~ max_temp
      <chr>                                                    <int64>                      <int>
    1 2014-01-06 08:00:00.000000+00:00,2014-01-06 08:10:00.00~ 2314993                         99
    2 2014-01-06 08:10:00.000000+00:00,2014-01-06 08:20:00.00~ 2314994                        100
    3 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:10:00.00~ 2314999                         79
    4 2014-01-06 10:00:00.000000+00:00,2014-01-06 10:10:00.00~ 2315005                         56
    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                         82