c2p_nest | R Documentation |
A sophisticated data transformation tool for generating column pair combinations and creating nested data structures with advanced configuration options.
c2p_nest(data, cols2bind, by = NULL, pairs_n = 2, sep = "-", nest_type = "dt")
data |
Input
|
cols2bind |
Column specification for pair generation
|
by |
Optional grouping specification
|
pairs_n |
|
sep |
|
nest_type |
Output nesting format
|
Advanced Transformation Mechanism:
Input validation and preprocessing
Dynamic column combination generation
Flexible pair transformation
Nested data structure creation
Transformation Process:
Validate input parameters and column specifications
Convert numeric indices to column names if necessary
Generate column combinations
Create subset data tables
Merge and nest transformed data
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 cols2bind and by parameters
data table
containing nested transformation results
Includes pairs
column identifying column combinations
Contains data
column storing nested data structures
Supports optional grouping variables
Key Operation Constraints:
Requires non-empty input data
Column specifications must be valid (either names or indices)
Supports flexible combination strategies
Computational complexity increases with combination size
utils::combn()
Combination generation
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.