stack_into_n_columns: Stack data into n columns.

stack_into_n_columnsR Documentation

Stack data into n columns.

Description

Reshapes the data to an n column structure for easy use in documents. Pads empty lines between variables and can include their names as well. Outputs a character matrix.

Usage

stack_into_n_columns(
  data,
  columns,
  pad_columns = TRUE,
  include_colnames = TRUE,
  rowname_colnames = "name"
)

Arguments

data

(data.frame, matrix, or something coercible into a matrix) The data to reshape.

columns

(whole number scalar) How many columns to stack the data into.

pad_columns

(logical) Whether to pad empty columns to the data if the data and column dimensions do fit divide into a whole number. Defaults to TRUE.

include_colnames

(logical) Whether to include the column names in the output. Defaults to TRUE.

rownames_colnames

(character scalar) If adding colnames in rows, which rownames should these be given? Defaults to "name".

Examples

df = split_every_k(1:12, 2) %>% as.data.frame
stack_into_n_columns(df, 2)
stack_into_n_columns(df, 3)
stack_into_n_columns(df, 4)

Deleetdk/kirkegaard documentation built on Feb. 28, 2025, 5:04 p.m.