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
ft:locale
en-US
ft:lastEdition
2024-05-03
dita:id
TeradataR_FxRef_Enterprise_1720
lifecycle
latest
Product Category
Teradata Vantage

Histogram

Description

The td_histogram_sqle() function calculates the frequency distribution of a data set using any of these methods:

  • Sturges

  • Scott

  • Variable-width

  • Equal-width

Notes:

  • This function requires the UTF8 client character set for UNICODE data.

  • This function does not support Pass Through Characters (PTCs).

  • This function does not support KanjiSJIS or Graphic data types.

Usage

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

Arguments

data

Required Argument.
Specifies the input tbl_teradata.
Types: tbl_teradata

object

Required when "method.type" is 'VARIABLE-WIDTH', optional otherwise.
Specifies the bin data.
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.

  • VARIABLE-WIDTH - Requires "object" argument, which specifies the minimum value and the maximum value of the bin.
    When one target column is specified, specify the minimum value in column1 in "object" data , maximum value in column2 in "object" data, and label of the bin in column3.
    When more than one target column is specified, specify the column name present in "target_column" attribute in column1 in "object" data, minimum value in column2 in "object" data, maximum value in column3 in "object" data, and the label of the bin in column4 in "object" data.
    Note: * The maximum number of bins cannot exceed 10000 per column.

  • EQUAL-WIDTH - 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 "object" argument is optional.
    When "object" data is omitted, td_histogram_sqle() function internally computes the min value and max value from the input data for the target columns.
    When "object" data is specified, the user can specify in the following manner: * When one target column is specified, specify min value in column1 in "object" data and max value in column2 in "object" data. * When more than one target column is specified, specify the column name present in "target_column" attribute in column1 in "object" data, min value in column2 in "object" data, and max value in column3 in "object" data.

Types: character

nbins

Required when "method.type" is 'VARIABLE-WIDTH' and 'EQUAL-WIDTH', optional otherwise.
Specifies the number of bins.
Notes:

  • When only one value is specified, it is applied to all the target columns. Otherwise, the number of "nbins" values must be equal to the number of target columns.

  • The maximum "nbins" value is 10000.

Default Value: 1
Types: integer OR vector of integers

inclusion

Optional Argument.
Specifies whether points on bin boundaries should be included in the
bin on the left or the right.
Note:

  • When only one value is specified, it is applied to all the target columns. Otherwise, the number of "inclusion" values must be equal to the number of target columns.

Default Value: "LEFT"
Permitted Values: LEFT, RIGHT
Types: character OR vector of Strings (character)

groupby.columns

Optional Argument.
Specifies the names of the input data columns that contain the group
values for binning.
Notes:

  • This argument must not have columns that are already specified in "target.columns".

  • This argument does not support range.

  • The maximum number of unique columns in the "groupby.columns" argument is 2042.

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 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_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'.
    obj1 <- td_histogram_sqle(data=titanic_data,
                              target.columns="age",
                              method.type="STURGES")
    
    # Print the result.
    print(obj1$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.
    obj2 <- td_histogram_sqle(data=titanic_data,
                              object=min_max_object,
                              target.columns="age",
                              method.type="VARIABLE-WIDTH",
                              nbins=3)
    
    # Print the result.
    print(obj2$result)
    
    # Example 3: Get the frequency distribution of a data set with respect
    #            to 'sex' column using 'EQUAL-WIDTH' method type for the
    #            values in column 'age' and 'fare' with 3 and 2 number
    #            of bins respectively.
    obj3 <- td_histogram_sqle(data=titanic_data,
                              target.columns=c("age", "fare"),
                              method.type="EQUAL-WIDTH",
                              nbins=c(3,2),
                              groupby.columns=c("sex"))
    
    # Print the result.
    print(obj3$result)