expand_df: Expand a data frame.

Description Usage Arguments Details Value Examples

View source: R/epi_functions.R

Description

expand_df expands a data frame by a vector of frequencies.

Usage

1
expand_df(aggregate.data, index.var = "Freq", retain.freq = FALSE)

Arguments

aggregate.data

A data frame.

index.var

A numerical variable with the frequencies (counts).

retain.freq

Logical expression indicating if frequencies should be kept.

Details

This is a generic function that resembles weighted frequencies in other statistical packages (for example, Stata). expand.df was adapted from a function developed by deprecated package epicalc (now package epiDisplay).

Value

An expanded data frame with replicates given by the frequencies.

Examples

1
2
3
4
5
6
7
Freq <- c(5032, 5095, 41, 204)
Mortality <- gl(2, 2, labels=c("No", "Yes"))
Calcium <- gl(2, 1, 4, labels=c("No", "Yes"))
anyca <- data.frame(Freq, Mortality, Calcium)
anyca
anyca.exp <- expand_df(anyca)
with(anyca.exp, table(Calcium, Mortality))

pubh documentation built on Feb. 17, 2021, 1:08 a.m.