expand_df: Expand a data frame.

View source: R/epi_functions.R

expand_dfR Documentation

Expand a data frame.

Description

expand_df expands a data frame by a vector of frequencies.

Usage

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

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 Oct. 8, 2024, 9:08 a.m.