Description
The Pivot function pivots data that is stored in rows into columns.
It outputs a tbl_teradata whose columns are based on the individual values
from an input tbl_teradata column. The schema of the output tbl_teradata depends on
the arguments to the function. The columns in the output tbl_teradata appear
in the order specified by the "data.order.column" argument.
The function handles missing or NULL values automatically.
Usage
td_pivot_mle (
data = NULL,
partition.columns = NULL,
target.columns = NULL,
pivot.column = NULL,
pivot.keys = NULL,
numeric.pivotkey = FALSE,
num.rows = NULL,
data.sequence.column = NULL,
data.partition.column = NULL,
data.order.column = NULL
)
Arguments
data |
Required Argument. |
data.partition.column |
Required Argument. |
data.order.column |
Optional Argument. |
partition.columns |
Required Argument. |
target.columns |
Required Argument. |
pivot.column |
Optional Argument.
|
pivot.keys |
Optional Argument. Required if you specify "pivot.column". |
numeric.pivotkey |
Optional Argument. |
num.rows |
Optional Argument. |
data.sequence.column |
Optional Argument. |
Value
Function returns an object of class "td_pivot_mle" which is a named
list containing object of class "tbl_teradata".
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("pivot_example", "pivot_input")
# Create object(s) of class "tbl_teradata".
pivot_input <- tbl(con, "pivot_input")
# Example 1: This example specifies the "pivot.column" argument and with the
# "pivot.keys" argument, which specifies the values from the "pivot.column"
# to use as pivot keys. Because "pivot.keys" does not include 'dewpoint', the
# function ignores rows that include 'dewpoint'.
td_pivot_out1 <- td_pivot_mle(data = pivot_input,
data.partition.column = c("sn","city","week"),
data.order.column = c("week","attribute"),
partition.columns = c("sn","city", "week"),
target.columns = c("value1"),
pivot.column = "attribute",
pivot.keys = c("temp","pressure")
)
# Example 2: Specify the "num.rows" argument instead of specifying the "pivot.column" argument.
td_pivot_out2 <- td_pivot_mle(data = pivot_input,
data.partition.column = c("sn","city","week"),
data.order.column = c("week","attribute"),
partition.columns = c("sn","city", "week"),
target.columns = c("value1"),
num.rows = 3
)