ts.mode() | Teradata Package for R - ts.mode() - 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.mode() returns the mode of all values in each group. In the event of a tie between two or more values, a row per result is returned.

ts.mode() uses the argument "value.expression" to specify the column for which mode is to be computed.

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

  • Calculate the mode.
    > df_seq_mode <- df_seq_grp %>% summarise(mode_temp = ts.mode(temperature))
  • Print the results.
    > df_seq_mode %>% arrange(TIMECODE_RANGE, buoyid, mode_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, mode_temp
       TIMECODE_RANGE                                   `GROUP BY TIME(MINUTES(~ buoyid mode_temp
       <chr>                                            <int64>                   <int>     <int>
     1 2014-01-06 08:00:00.000000+00:00,2014-01-06 08:~ 35345                         0        10
     2 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:~ 35347                         1        70
     3 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:~ 35347                         1        71
     4 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:~ 35347                         1        72
     5 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:~ 35347                         1        77
     6 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:~ 35347                         1        78
     7 2014-01-06 09:00:00.000000+00:00,2014-01-06 09:~ 35347                         1        79
     8 2014-01-06 10:00:00.000000+00:00,2014-01-06 10:~ 35349                        44        43
     9 2014-01-06 10:30:00.000000+00:00,2014-01-06 11:~ 35350                        22        23
    10 2014-01-06 10:30:00.000000+00:00,2014-01-06 11:~ 35350                        44        43
    # ... with more rows

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

  • Calculate the mode.
    > df_nonpti_mode <- df_nonpti_grp %>% summarise(mode_temp = ts.mode(temperature))
  • Print the results.
    > df_nonpti_mode %>% arrange(TIMECODE_RANGE, mode_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, mode_temp
       TIMECODE_RANGE                                          `GROUP BY TIME(MINUTES(~ mode_temp
       <chr>                                                   <int64>                      <int>
     1 2014-01-06 08:00:00.000000+00:00,2014-01-06 08:01:00.0~ 23149921                        10
     2 2014-01-06 08:01:00.000000+00:00,2014-01-06 08:02:00.0~ 23149922                        10
     3 2014-01-06 08:02:00.000000+00:00,2014-01-06 08:03:00.0~ 23149923                        10
     4 2014-01-06 08:03:00.000000+00:00,2014-01-06 08:04:00.0~ 23149924                        10
     5 2014-01-06 08:04:00.000000+00:00,2014-01-06 08:05:00.0~ 23149925                        10
     6 2014-01-06 08:05:00.000000+00:00,2014-01-06 08:06:00.0~ 23149926                        10
     7 2014-01-06 08:06:00.000000+00:00,2014-01-06 08:07:00.0~ 23149927                        10
     8 2014-01-06 08:07:00.000000+00:00,2014-01-06 08:08:00.0~ 23149928                        10
     9 2014-01-06 08:08:00.000000+00:00,2014-01-06 08:09:00.0~ 23149929                        NA
    10 2014-01-06 08:09:00.000000+00:00,2014-01-06 08:10:00.0~ 23149930                        99
    # ... with more rows