sprintf_data_frame: Create new columns in a data.frame with sprintf results

View source: R/sprintf_data_frame.R

sprintf_data_frameR Documentation

Create new columns in a data.frame with sprintf results

Description

Create new columns in a data.frame with sprintf results

Usage

sprintf_data_frame(data, ..., factor_out_if_factor_in = TRUE, ordered = NULL)

sprintf_data_frame_single(
  data,
  format,
  factor_out_if_factor_in = TRUE,
  ordered = NULL
)

Arguments

data

the data to use for formatting

...

a named list of character vectors. Names are new columns for data, and values are sent to format in sprintf_data_frame_single.

factor_out_if_factor_in

If any of the input columns are factors, make the output column a factor in the same order as the input column factors

ordered

If factor_out_if_factor_in converts the output to a factor, pass to base::factor. If NULL, then it is set to TRUE if any of the input columns are ordered factors.

format

A named character vector where the names are column names in data and the values are sprintf format strings for the column.

Value

The data frame with columns added for the names of ....

A character vector with one element per row of data.

Functions

  • sprintf_data_frame_single(): Generate a character vector based on sprintf input formats

Examples

sprintf_data_frame(
  data=mtcars,
  cyl_mpg=c(mpg="%g miles/gallon, ", cyl="%g cylinders"),
  disp_hp=c(disp="%g cu.in. displacement, ", hp="%g hp")
)
sprintf_data_frame_single(
  data=mtcars,
  format=c(mpg="%g miles/gallon, ", cyl="%g cylinders")
)

billdenney/bsd.report documentation built on Jan. 16, 2024, 12:54 a.m.