expand_df: Expand a data.frame

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/expand_df.R

Description

This function expands a data.frame based on a column (col.exp). Useful for generating long tables from contingency tables.

Usage

1
expand_df(x, col.exp, na.strings = "NA", as.is = FALSE, dec = ".")

Arguments

x

a data.frame

col.exp

a character string of the column name or the column number to use for "expansion"

na.strings

passed to type.convert

as.is

passed to type.convert

dec

passed to type.convert

Value

DF a data.frame of x in "long" format.

Author(s)

Modified version of expand.dft in the kmmisc package by Kevin Middleton which is based on Marc Schwartz' version from the r-help mailing list. Uses rindlist() from data.table package to speed-up the function.

References

See https://stat.ethz.ch/pipermail/r-help/2009-January/185561.html for discussion of expand_df().

See Also

table

Examples

1
2
3
4
5
OCAD <- data.frame(Sex = c("Male", "Female", "Male", "Female"),
                   Status = c("Present", "Present", "Absent", "Absent"),
                   Count = c(92, 15, 21, 20))
OCAD <- expand_df(OCAD, col.exp = "Count")
table(OCAD)

sumtxt/datatools documentation built on Oct. 7, 2018, 11:18 p.m.