Learn R Programming

crosstable (version 0.3.2)

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

Description

Generic function to compact a table (publication formatting)

Usage

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

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

Arguments

data

the object to compact

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

...

additional arguments (not used)

Value

a compacted data.frame

Examples

Run this code
# NOT RUN {
#dataframes
x=iris[c(1:5,51:55,101:105),]
compact(x, name_from="Species")
compact(x, name_from="Species", name_to="Petal.Length")

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

Run the code above in your browser using DataLab