Learn R Programming

hardhat (version 1.3.1)

recompose: Recompose a data frame into another form

Description

recompose() takes a data frame and converts it into one of:

  • A tibble

  • A data frame

  • A matrix

  • A sparse matrix (using the Matrix package)

This is an internal function used only by hardhat and recipes.

Usage

recompose(data, ..., composition = "tibble")

Value

The output type is determined from the composition.

Arguments

data

A data frame.

...

These dots are for future extensions and must be empty.

composition

One of:

  • "tibble" to convert to a tibble.

  • "data.frame" to convert to a base data frame.

  • "matrix" to convert to a matrix. All columns must be numeric.

  • "dgCMatrix" to convert to a sparse matrix. All columns must be numeric, and the Matrix package must be installed.

Examples

Run this code
df <- vctrs::data_frame(x = 1)

recompose(df)
recompose(df, composition = "matrix")

# All columns must be numeric to convert to a matrix
df <- vctrs::data_frame(x = 1, y = "a")
try(recompose(df, composition = "matrix"))

Run the code above in your browser using DataLab