Teradata Package for R Function Reference | 17.20 - Histogram - 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

Histogram

Description

Function calculates the frequency distribution of a data set using any of these methods:

  • Sturges

  • Scott

  • Variable-width

  • Equal-width

Usage

  td_histogram_sqle (
      data = NULL,
      object = NULL,
      target.columns = NULL,
      method.type = NULL,
      nbins = 1,
      inclusion = "LEFT",
      ...
  )

Arguments

data

Required Argument.
Specifies the input tbl_teradata.
Types: tbl_teradata

object

Optional Argument.
Specifies the bin data, needed when "method.type" is set to 'EQUAL-WIDTH' or 'VARIABLE-WIDTH'.
Types: tbl_teradata

target.columns

Required Argument.
Specifies the name(s) of the column(s) in "data" to perform computations on.
Types: character OR vector of Strings (character)

method.type

Required Argument.
Specifies the method type to be used for histogram computation.
Permitted Values:

  • STURGES - Algorithm for calculating bin width, w:
    w = r/(1 + log2n) where:
    w = bin width r = data value range n = number of elements in data set Sturges algorithm performs best if data is normally distributed and n is at least 30.

  • SCOTT - Algorithm for calculating bin width, w:
    w = 3.49s/(n^1/3) where:
    w = bin width s = standard deviation of data values n = number of elements in data set r = data value range Number of bins: r/w Scott algorithm performs best on normally distributed data.

  • EQUAL-WIDTH - Requires "object" argument, which specifies the minimum value and the maximum value of the bin in column1 and column2 respectively, and the label of the bin in column3. Maximum number of bins cannot exceed 3500.

  • VARIABLE-WIDTH - Requires "object" argument, which specifies the minimum value of the bins in column1 and the maximum value of the bins in column2.
    Algorithm for calculating bin width, w:
    w = (max - min)/k where:
    min = minimum value of the bins max = maximum value of the bins k = number of intervals into which algorithm divides data set Interval boundaries: min+w, min+2w, …, min+(k-1)w

Types: character

nbins

Optional Argument, Required when "method.type" is 'Variable-Width' and 'Equal-Width'.
Specifies the number of bins.
Default Value: 1
Types: integer

inclusion

Optional Argument.
Specifies whether points on bin boundaries should be included in the
bin on the left or the right.
Default Value: "LEFT"
Permitted Values: LEFT, RIGHT
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 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 SQLE Engine function supports, else an exception is raised.

Value

Function returns an object of class "td_histogram_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", "min_max_titanic")
    
    # Create tbl_teradata object.
    titanic_data <- tbl(con, "titanic")
    
    # Create tbl_teradata object for minimum and maximum value of bin
    # "Young age", "Middle Age" and, "Old Age".
    min_max_object <- tbl(con, "min_max_titanic")
    
    # Check the list of available analytic functions.
    display_analytic_functions()
    
    # Example 1: Get the frequency distribution of a data set using 'sturges'
    #            method type for the values in column 'age'.
    obj <- td_histogram_sqle(data=titanic_data,
                             target.columns="age",
                             method.type="Sturges")
    
    # Print the result.
    print(obj$result)
    
    # Example 2: Get the frequency distribution of a data set using 'variable-width'
    #            method type for the values in column 'age' with 3 number of bins.
    obj <- td_histogram_sqle(data=titanic_data,
                             object=min_max_object,
                             target.columns="age",
                             method.type="variable-width",
                             nbins=3)
    
    # Print the result.
    print(obj$result)