View source: R/data_tabulate.R
| as.prop.table | R Documentation |
as.prop.table() is an S3 generic. It can be used on objects of class
datawizard_crosstab created by data_tabulate() when it was run with the
arguments by and proportions.
as.prop.table(x, ...)
## S3 method for class 'datawizard_crosstab'
as.prop.table(x, remove_na = TRUE, simplify = FALSE, verbose = TRUE, ...)
## S3 method for class 'datawizard_tables'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
...,
stringsAsFactors = FALSE,
add_total = FALSE
)
## S3 method for class 'datawizard_table'
as.table(x, remove_na = TRUE, simplify = FALSE, verbose = TRUE, ...)
x |
An object created by |
... |
not used. |
remove_na |
Logical, if |
simplify |
Logical, if |
verbose |
Toggle warnings and messages. |
row.names |
|
optional |
logical. If |
stringsAsFactors |
logical: should the character vector be converted to a factor? |
add_total |
For crosstables (i.e. when |
data_tabulate
data(efc)
# Some cross tabulation
cross <- data_tabulate(efc, select = "e42dep", by = "c172code", proportions = "row")
cross
# Convert to a propensity table
as.prop.table(cross)
# Convert to data.frame
result <- data_tabulate(efc, "c172code", by = "e16sex")
as.data.frame(result)
as.data.frame(result)$table
as.data.frame(result, add_total = TRUE)$table
# Convert to a table that can be passed to chisq.test()
out <- data_tabulate(efc, "c172code", by = "e16sex")
# we need to simplify the output, else we get a list of tables
tbl <- as.table(out, simplify = TRUE)
tbl
suppressWarnings(chisq.test(tbl))
# apply chisq.test to each table
out <- data_tabulate(efc, c("c172code", "e16sex"))
suppressWarnings(lapply(as.table(out), chisq.test))
# can also handle grouped data frames
d <- data_group(mtcars, "am")
x <- data_tabulate(d, "cyl", by = "gear")
as.table(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.