A sophisticated data transformation tool for performing row pair conversion and creating nested data structures with advanced configuration options.

r2p_nest(data, rows2bind, by, nest_type = "dt")

Arguments

data

Input data frame or data table

  • Must contain valid columns for transformation

  • Supports multiple data types

rows2bind

Row binding specification

  • Can be a character column name

  • Can be a numeric column index

  • Must be a single column identifier

by

Grouping specification for nested pairing

  • Can be a character vector of column names

  • Can be a numeric vector of column indices

  • Must specify at least one column

  • Supports multi-column transformation

nest_type

Output nesting format

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

  • "df": Returns nested data frame

Value

data table containing nested transformation results

  • Includes name column identifying source columns

  • Contains data column storing nested data structures

Details

Advanced Transformation Mechanism:

  1. Input validation and preprocessing

  2. Dynamic column identification

  3. Flexible row pairing across specified columns

  4. Nested data structure generation

Transformation Process:

  • Validate input parameters and column specifications

  • Convert numeric indices to column names if necessary

  • Reshape data from wide to long format

  • Perform column-wise nested transformation

  • Generate final nested structure

Column Specification:

  • Supports both column names and numeric indices

  • Numeric indices must be within valid range (1 to ncol)

  • Column names must exist in the dataset

  • Flexible specification for both rows2bind and by parameters

Note

Key Operation Constraints:

  • Requires non-empty input data

  • Column specifications must be valid (either names or indices)

  • By parameter must specify at least one column

  • Low computational overhead

See also

Examples

# Example 1: Row-to-pairs nesting with column names
r2p_nest(
  mtcars,                     # Input mtcars dataset
  rows2bind = "cyl",          # Column to be used as row values
  by = c("hp", "drat", "wt")  # Columns to be transformed into pairs
)
#>      name                data
#>    <fctr>              <list>
#> 1:     hp <data.table[32x12]>
#> 2:   drat <data.table[32x12]>
#> 3:     wt <data.table[32x12]>
# Returns a nested data.table where:
# - name: variable names (hp, drat, wt)
# - data: list column containing data.tables with rows grouped by cyl values

# Example 2: Row-to-pairs nesting with numeric indices
r2p_nest(
  mtcars,                     # Input mtcars dataset
  rows2bind = 2,              # Use 2nd column (cyl) as row values
  by = 4:6                    # Use columns 4-6 (hp, drat, wt) for pairs
)
#>      name                data
#>    <fctr>              <list>
#> 1:     hp <data.table[32x12]>
#> 2:   drat <data.table[32x12]>
#> 3:     wt <data.table[32x12]>
# Returns a nested data.table where:
# - name: variable names from columns 4-6
# - data: list column containing data.tables with rows grouped by cyl values