dm (version 0.0.3.9003)

decompose_table: Decompose a table into two linked tables

Description

Perform table surgery by extracting a 'parent table' from a table, linking original and new table by a key and returning both.

decompose_table() accepts a data frame, a name for an 'ID column' that will be newly created, and the names of the columns which will be extracted into the new data frame.

It creates the 'parent table', consisting of the columns specified in the ellipsis and the new 'ID column'. Then it removes the said columns from the now called 'child table' (the original table) and also adds the 'ID column' here appropriately.

Usage

decompose_table(.data, new_id_column, ...)

Arguments

.data

Data frame from which columns ... are to be extracted.

new_id_column

Name of the identifier column (primary key column) for the parent table. A column of this name is also added in 'child table'.

...

The columns to be extracted from the .data.

One or more unquoted expressions separated by commas. You can treat variable names like they are positions, so you can use expressions like x:y to select ranges of variables.

The arguments in ... are automatically quoted and evaluated in a context where column names represent column positions. They also support unquoting and splicing. See vignette("programming") for an introduction to these concepts.

See select helpers for more details and examples about tidyselect helpers such as starts_with(), everything(), ...

See Also

Other table surgery functions: reunite_parent_child

Examples

Run this code
# NOT RUN {
library(magrittr)

decomposed_table <- decompose_table(mtcars, new_id, am, gear, carb)
decomposed_table$child_table
decomposed_table$parent_table
# }

Run the code above in your browser using DataLab