Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

counts_to_cases

Convert a Table of Counts into a Data Frame of cases


Description

converts a contingency table or a data frame of counts into a data frame of individual observations.

Usage

counts_to_cases(x, count.col = "Freq")

Arguments

x

a contingency table or a data frame

count.col

the name of the column containing the counts. Default is "Freq".

Value

a data frame of cases

Examples

# Create a cross-tabulation demo data
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xtab <- as.table(
  rbind(c(20, 5), c(16,9))
)
dimnames(xtab) <- list(
  before = c("non.smoker", "smoker"),
  after = c("non.smoker", "smoker")
)
xtab

# Convert into a data frame of cases
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
df <- counts_to_cases(xtab)
head(df)

rstatix

Pipe-Friendly Framework for Basic Statistical Tests

v0.7.0
GPL-2
Authors
Alboukadel Kassambara [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.