Teradata Package for R Function Reference | 17.20 - MovingAverage - Teradata Package for R - Look here for syntax, methods and examples for the functions included in the Teradata Package for R.

Teradata® Package for R Function Reference

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-05-03
dita:id
TeradataR_FxRef_Enterprise_1720
Product Category
Teradata Vantage

MovingAverage

Description

td_moving_average_sqle() function computes average values in a series, using the specified moving average type.

Usage

  td_moving_average_sqle (
      data = NULL,
      target.columns = NULL,
      alpha = 0.1,
      start.rows = 2,
      window.size = 10,
      include.first = FALSE,
      mavgtype = "C",
      ...
  )

Arguments

data

Required Argument.
Specifies the name of the tbl_teradata that contains the columns.
Types: tbl_teradata

target.columns

Optional Argument.
Specifies the input column names for which the moving average is to be computed. If you omit this argument, then the function copies every input column to the output tbl_teradata but does not compute moving average.
Types: character OR vector of Strings (character)

alpha

Optional Argument.
Specifies the damping factor, a value in the range [0, 1], which represents a percentage in the range [0, 100]. For example, if alpha is 0.2, then the damping factor is 20 older observations faster.
Default Value: 0.1
Types: float

start.rows

Optional Argument.
Specifies the number of rows at the beginning of the time series that the function "skips" before it begins the calculation of the exponential moving average. The function uses the arithmetic average of these rows as the initial value of the exponential moving average.
The value n must be an integer.
Default Value: 2
Types: integer

window.size

Optional Argument.
Specifies the number of previous values to include in the computation of the simple moving average.
Default Value: 10
Types: integer

include.first

Optional Argument.
Specifies whether the first "start.rows" rows should be included in the output or not.
Default Value: FALSE
Types: logical

mavgtype

Optional Argument.
Specifies the moving average type that needs to be used for computing moving averages of TargetColumns.
Default Value: "C"
Permitted Values: C, S, M, W, E, T
Types: character

...

Specifies the generic keyword arguments SQLE functions accept.
Below are the generic keyword arguments:

persist:
Optional Argument.
Specifies whether to persist the results of the function in a table or not.
When set to TRUE, results are persisted in a table; otherwise, results are garbage collected at the end of the session.
Default Value: FALSE
Types: logical

volatile:
Optional Argument.
Specifies whether to put the results of the function in a volatile table or not.
When set to TRUE, results are stored in a volatile table, otherwise not.
Default Value: FALSE
Types: logical

Function allows the user to partition, hash, order or local order the input data. These generic arguments are available for each argument that accepts tbl_teradata as input and can be accessed as:

  • "<input.data.arg.name>.partition.column" accepts character OR vector of Strings (character) (Strings)

  • "<input.data.arg.name>.hash.column" accepts character OR vector of Strings (character) (Strings)

  • "<input.data.arg.name>.order.column" accepts character OR vector of Strings (character) (Strings)

  • "local.order.<input.data.arg.name>" accepts logical

Note:
These generic arguments are supported by tdplyr if the underlying SQL Engine function supports, else an exception is raised.

Value

Function returns an object of class "td_moving_average_sqle" which is a named list containing object of class "tbl_teradata".
Named list member(s) can be referenced directly with the "$" operator using the name(s):result

Examples

  
    
    # Get the current context/connection.
    con <- td_get_context()$connection
    
    # Load the example data.
    loadExampleData("exponentialmovavg_example", "ibm_stock")
    
    # Create tbl_teradata object.
    ibm_stock <- tbl(con, "ibm_stock")
    
    # Check the list of available analytic functions.
    display_analytic_functions()
    
    # Example 1: Compute the average values in a series, using the 'C' moving average type.
    obj <- td_moving_average_sqle(data=ibm_stock,
                                  data.partition.column='stockprice',
                                  data.order.column='stockprice',
                                  include.first=FALSE,
                                  alpha=0.1,
                                  start.rows=2,
                                  window.size=10,
                                  mavgtype='C')
    
    # Print the result.
    print(obj$result)