Learn R Programming

crosstable (version 0.8.0)

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

Description

Generic function to compact a table (publication formatting)

Usage

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

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

Value

a compacted data.frame

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::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})".

Author

Dan Chaltiel

Examples

Run this code
#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")

Run the code above in your browser using DataLab