ct_compact {crosstable}R 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",
  wrap_cols = NULL,
  rtn_flextable = FALSE,
  ...
)

## S3 method for class 'crosstable'
ct_compact(
  data,
  name_from = c("label", ".id"),
  name_to = "variable",
  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.

wrap_cols

name of the columns to wrap

rtn_flextable

whether to return a formatted 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")

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

[Package crosstable version 0.7.0 Index]