ct_compact: Generic function to compact a table (publication formatting)

View source: R/compact.R

ct_compactR Documentation

Generic function to compact a table (publication formatting)

Description

Generic function to compact a table (publication formatting)

Usage

## S3 method for class 'data.frame'
ct_compact(
  data,
  name_from,
  name_to = "variable",
  ...,
  id_from = name_from,
  wrap_cols = NULL,
  rtn_flextable = FALSE
)

## S3 method for class 'crosstable'
ct_compact(
  data,
  name_from = c("label", ".id"),
  name_to = "variable",
  id_from = ".id",
  keep_id = FALSE,
  ...
)

Arguments

data

the object to compact

...

additional arguments (not used)

name_from

name of the column to be collapsed when compacting

name_to

name of the column that will receive the collapsed column. Will be created if it doesn't exist.

id_from

name of the columns to use as cut-off. Useful when successive name_from have the same value.

wrap_cols

name of the columns to wrap

rtn_flextable

whether to return a formatted flextable::flextable() object or a simple data.frame

keep_id

glue pattern to keep the column name along with the label. If TRUE, default to "{label} ({.id})".

Value

a compacted data.frame

Author(s)

Dan Chaltiel

Examples

#dataframes
x=iris[c(1:5,51:55,101:105),]
ct_compact(x, name_from="Species")
ct_compact(x, name_from="Species", name_to="Petal.Length")
x$Species2 = substr(x$Species, 1, 1)
ct_compact(x, name_from="Species", wrap_cols="Species2")
ct_compact(x, name_from="Species", id_from="Species2") #cut on "v"

#crosstables
x=crosstable(mtcars2, c(disp,hp,am), by=vs, test=TRUE, effect=TRUE)
ct_compact(x)
ct_compact(x, name_from=".id")

crosstable documentation built on Nov. 1, 2024, 5:06 p.m.