c2p_nest {mintyr}R Documentation

Column to Pair Nested Transformation

Description

A sophisticated data transformation tool for generating column pair combinations and creating nested data structures with advanced configuration options.

Usage

c2p_nest(data, cols2bind, by = NULL, pairs_n = 2, sep = "-", nest_type = "dt")

Arguments

data

Input ⁠data frame⁠ or ⁠data table⁠

  • Must contain valid columns for transformation

  • Supports multiple data types

cols2bind

Column specification for pair generation

  • Can be a character vector of column names

  • Can be a numeric vector of column indices

  • Must reference existing columns in the dataset

by

Optional grouping specification

  • Can be a character vector of column names

  • Can be a numeric vector of column indices

  • Enables hierarchical nested transformations

  • Supports multi-level aggregation

  • Default is NULL

pairs_n

numeric indicating combination size

  • Minimum value: 2

  • Maximum value: Length of cols2bind

  • Controls column pair complexity

  • Default is 2

sep

character separator for pair naming

  • Used in generating combination identifiers

  • Must be a single character

  • Default is "-"

nest_type

Output nesting format

  • "dt": Returns nested ⁠data table⁠ (default)

  • "df": Returns nested ⁠data frame⁠

Details

Advanced Transformation Mechanism:

  1. Input validation and preprocessing

  2. Dynamic column combination generation

  3. Flexible pair transformation

  4. Nested data structure creation

Transformation Process:

Column Specification:

Value

⁠data table⁠ containing nested transformation results

Note

Key Operation Constraints:

See Also

Examples

# Example data preparation: Define column names for combination
col_names <- c("Sepal.Length", "Sepal.Width", "Petal.Length")

# Example 1: Basic column-to-pairs nesting with custom separator
c2p_nest(
  iris,                   # Input iris dataset
  cols2bind = col_names,  # Columns to be combined as pairs
  pairs_n = 2,            # Create pairs of 2 columns
  sep = "&"               # Custom separator for pair names
)
# Returns a nested data.table where:
# - pairs: combined column names (e.g., "Sepal.Length&Sepal.Width")
# - data: list column containing data.tables with value1, value2 columns

# Example 2: Column-to-pairs nesting with numeric indices and grouping
c2p_nest(
  iris,                   # Input iris dataset
  cols2bind = 1:3,        # First 3 columns to be combined
  pairs_n = 2,            # Create pairs of 2 columns
  by = 5                  # Group by 5th column (Species)
)
# Returns a nested data.table where:
# - pairs: combined column names
# - Species: grouping variable
# - data: list column containing data.tables grouped by Species

[Package mintyr version 0.1.0 Index]