r2p_nest | R Documentation |
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")
data |
Input
|
rows2bind |
Row binding specification
|
by |
Grouping specification for nested pairing
|
nest_type |
Output nesting format
|
Advanced Transformation Mechanism:
Input validation and preprocessing
Dynamic column identification
Flexible row pairing across specified columns
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
data table
containing nested transformation results
Includes name
column identifying source columns
Contains data
column storing nested data structures
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
data.table::melt()
Long format conversion
data.table::dcast()
Wide format conversion
base::rbind()
Row binding utility
c2p_nest()
Column to pair nested transformation
# 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
)
# 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
)
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.