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

Teradata® R Package Function Reference

Product
Teradata R Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-28
dita:id
B700-4007
lifecycle
previous
Product Category
Teradata Vantage

Description

The CumulativeMovAvg function computes the cumulative moving average of a value from the beginning of a series.
When computing cumulative moving average, the data are added to the data set in an ordered data stream over time. The objective is to compute the average of all the data at each point in time when new data arrived.

Usage

  td_cumulative_mov_avg_mle (
      data = NULL,
      target.columns = NULL,
      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 the Partition By columns for data.
Values to this argument can be provided as vector, if multiple columns are used for ordering.
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 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 object but does not compute moving average.

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_cumulative_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("cumulativemovavg_example", "ibm_stock")
    
    # Create remote tibble objects.
    ibm_stock <- tbl(con, "ibm_stock")
    
    # Compute the cumulative moving average for "stockprice".
    td_cumulative_mov_avg_out <- td_cumulative_mov_avg_mle(data = ibm_stock,
                                                       data.partition.column = c("name"),
                                                       data.order.column = c("period"),
                                                       target.columns = c("stockprice")
                                                       )