Description Usage Arguments Value Author(s) References See Also Examples
This function expands a data.frame
based on a column (col.exp
). Useful for generating long tables from contingency tables.
1 | expand.dft(x, col.exp, na.strings = "NA", as.is = FALSE, dec = ".")
|
x |
a |
col.exp |
a character string of the column name or the column number to use for "expansion" |
na.strings |
passed to |
as.is |
passed to |
dec |
passed to |
DF |
a |
Modified for the abd
package by Kevin Middleton from a function posted by Marc Schwartz to the r-help mailing list.
See https://stat.ethz.ch/pipermail/r-help/2009-January/185561.html for discussion of expand.dft()
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | data(Aspirin)
Aspirin
# Specifying col.exp as character
Aspirin.expanded <- expand.dft(Aspirin, "count")
str(Aspirin.expanded)
xtabs(~treatment + cancer, Aspirin.expanded)
# Specifying col.exp as numeric
Aspirin.expanded <- expand.dft(Aspirin, 3)
str(Aspirin.expanded)
xtabs(~treatment + cancer, Aspirin.expanded)
# Plot 2X2 Contingency tables
plot( ~ treatment + cancer, data = Aspirin.expanded)
plot(table(Aspirin.expanded), main = "")
mosaicplot(~treatment + cancer, Aspirin.expanded)
# much nicer looking plots using vcd
if(require(vcd)) {
mosaic(~treatment + cancer, Aspirin.expanded)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.