ct_compact | R Documentation |
Generic function to compact a table (publication formatting)
## 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,
...
)
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 |
wrap_cols |
name of the columns to wrap |
rtn_flextable |
whether to return a formatted |
keep_id |
|
a compacted data.frame
Dan Chaltiel
#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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.