Teradata R Package Function Reference - Pack - 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 Pack function packs data from multiple input columns into a single column. The packed column has a virtual column for each input column. By default, virtual columns are separated by commas and each virtual column value is labeled with its column name.

Usage

  td_pack_mle (
    data = NULL,
    input.columns = NULL,
    output.column = NULL,
    delimiter = ",",
    include.column.name = TRUE
  )

Arguments

data

Required Argument.
Specifies the tbl_teradata containing the input attributes.

input.columns

Optional Argument.
Specifies the names of the input columns to pack into a single output column. These names become the column names of the virtual columns. By default, all input tbl_teradata columns are packed into a single output column. If you specify this argument, but do not specify all input tbl_teradata columns, the function copies the unspecified input table columns to the output table.

output.column

Required Argument.
Specifies the name to give to the packed output column.

delimiter

Optional Argument.
Specifies the delimiter (a string) that separates the virtual columns in the packed data.
Default Value: ","

include.column.name

Optional Argument.
Specifies whether to label each virtual column value with its column name (making the virtual column "input_column:value").
Default Value: TRUE

Value

Function returns a named list containing Teradata tbl object. Named list members 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("pack_example", "ville_temperature")
    
    # Create remote tibble objects.
    ville_temperature <- tbl(con, "ville_temperature")
    
    # Example 1 -
    td_pack_out1 <- td_pack_mle(data = ville_temperature,
                      input.columns = c("city", "state", "period", "temp_f"),
                      output.column = "packed_data",
                      delimiter = ",",
                      include.column.name = TRUE
                      )
    
    # Example 2 -
    td_pack_out2 <- td_pack_mle(data = ville_temperature,
                      input.columns = c("city", "state", "period", "temp_f"),
                      output.column = "packed_data",
                      delimiter = "|",
                      include.column.name = FALSE
                      )