Teradata Package for R Function Reference | 17.20 - BincodeTransform - 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
ft:locale
en-US
ft:lastEdition
2024-05-03
dita:id
TeradataR_FxRef_Enterprise_1720
Product Category
Teradata Vantage

BincodeTransform

Description

The td_bincode_transform_sqle() function is used to convert the continuous numeric data to categorical data. The td_bincode_transform_sqle() function takes the output of td_bincode_fit_sqle() function to apply the transform on input tbl_teradata.
td_bincode_transform_sqle() function takes two tbl_teradata objects as input:

  1. Input tbl_teradata which contains numeric data to be converted to categorical data.

  2. Output of td_bincode_fit_sqle() function which contains the binning data.

Usage

  td_bincode_transform_sqle(
      data = NULL,
      object = NULL,
      accumulate = NULL,
      ...
  )

Arguments

data

Required Argument.
Specifies the input tbl_teradata.
Types: tbl_teradata

object

Required Argument.
Specifies the tbl_teradata containing the binning parameters generated by td_bincode_fit_sqle() function or the instance of td_bincode_fit_sqle.
Types: tbl_teradata or td_bincode_fit_sqle

accumulate

Optional Argument.
Specifies the name(s) of input tbl_teradata column(s) to copy to the output. By default, the function copies no input columns to the output.
Types: character OR vector of Strings (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 table or not. When set to TRUE, results are persisted in 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 volatile table or not. When set to TRUE, results are stored in 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_bincode_transform_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("tdplyr_example", "titanic", "bin_fit_ip")
    
    # Create tbl_teradata object.
    titanic_data <- tbl(con, "titanic")
    bin_fit_ip <- tbl(con, "bin_fit_ip")
    
    # Check the list of available analytic functions.
    display_analytic_functions()
    
    # Example 1: Convert the continuous numeric data in the column 'age' to
    #            categorical data.
    
    # First generate a model using td_bincode_fit_sqle() function to bin-code the values
    # in column 'age' using the 'Variable-Width' method type.
    bin_code_1 <- td_bincode_fit_sqle(data=titanic_data,
                                      fit.data=bin_fit_ip,
                                      fit.data.order.column = c('minVal', 'maxVal'),
                                      target.columns='age',
                                      minvalue.column='minVal',
                                      maxvalue.column='maxVal',
                                      label.column='label',
                                      method.type='Variable-Width',
                                      label.prefix='label_prefix'
                                     )
    
    # Apply the transformation on the input data using the model generated above.
    # Note the model is passed as a tbl_teradata.
    obj <- td_bincode_transform_sqle(data=titanic_data,
                                     object=bin_code_1$result,
                                     object.order.column="TD_MinValue_BINFIT",
                                     accumulate=c('passenger', 'ticket')
                                    )
    
    # Print the result.
    print(obj$result)
    
    # Example 2: Convert the continuous numeric data in the column 'age' to
    #            categorical data.
    
    # First generate a model using td_bincode_fit_sqle() function to bin-code the values
    # in column 'age' using the 'Equal-Width' method type.
    bin_code_2 <- td_bincode_fit_sqle(data=titanic_data,
                                      target.columns='age',
                                      method.type='Equal-Width',
                                      nbins=2,
                                      label.prefix='label_prefix'
                                     )
    
    # Apply the transformation on the input data using the model generated above.
    # Note that model is passed as an instance of td_bincode_fit_sqle to "object".
    obj <- td_bincode_transform_sqle(data=titanic_data,
                                     object=bin_code_2$result,
                                     accumulate=c('passenger', 'ticket')
                                    )
    
    # Print the result.
    print(obj$result)
    
    
    # Alternatively use S3 transform function to run transform on the output of
    # td_bincode_fit_sqle() function.
     obj <- transform(bin_code_2,
                      data=titanic_data,
                      accumulate=c('passenger', 'ticket')
                      )
                      
    # Print the result.
    print(obj$result)