Teradata R Package Function Reference - 16.20 - SimpleMovAvg - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
16.20
created_date
February 2020
category
Programming Reference
featnum
B700-4007-098K

Description

The SimpleMovAvg function computes the simple moving average of points in a series.

Usage

  td_simple_mov_avg_mle (
      data = NULL,
      target.columns = NULL,
      include.first = FALSE,
      window.size = 10,
      data.sequence.column = NULL,
      data.partition.column = NULL,
      data.order.column = NULL
  )

Arguments

data

Required Argument.
Specifies the input tbl object of class "tbl_teradata" that contains the columns.

data.partition.column

Required Argument.
Specifies Partition By columns for data.
Values to this argument can be provided as vector, if multiple columns are used for partition.
Types: character OR vector of Strings (character)

data.order.column

Required Argument.
Specifies the Order By columns for data.
Values to this argument can be provided as vector, if multiple columns are used for ordering.

target.columns

Optional Argument.
Specifies the names of the input columns 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 object but does not compute moving average.

include.first

Optional Argument.
Specifies whether to include the starting rows in the output table. If you specify TRUE, the output columns for the starting rows contain NA, because their simple moving average is undefined.
Default Value: FALSE

window.size

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

data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "data". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.

Value

Function returns an object of class "td_simple_mov_avg_mle" which is a named list containing Teradata tbl object. Named list member can be referenced directly with the "$" operator using name: result

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("simplemovavg_example", "ibm_stock")
    
    # Create remote tibble objects.
    ibm_stock <- tbl(con, "ibm_stock")
    
    # Compute the simple moving average for "stockprice".
    # This also includes the first 9 rows with moving average NA.
    td_simple_mov_avg_out <- td_simple_mov_avg_mle(data = ibm_stock,
                                           data.partition.column = "name",
                                           data.order.column = "period",
                                           target.columns = "stockprice",
                                           include.first = TRUE,
                                           window.size = 10
                                           )