decompose_table {dm}R Documentation

Decompose a table into two linked tables



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

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

It creates a 'parent table', which consists of the columns specified in the ellipsis, and a new 'ID column'. Then it removes those columns from the original table, which is now called the 'child table, and adds the 'ID column'.


decompose_table(.data, new_id_column, ...)



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


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 as if they were 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 those concepts.

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


A named list of length two:

Life cycle

This function is marked "questioning" because it feels more useful when applied to a table in a dm object.

See Also

Other table surgery functions: reunite_parent_child()


decomposed_table <- decompose_table(mtcars, new_id, am, gear, carb)

[Package dm version 0.2.8 Index]