counts_df: Create counts and frequencies within in data frame

View source: R/counts_df.r

counts_dfR Documentation

Create counts and frequencies within in data frame

Description

This function calculates and reports counts and frequencies stratified by one or more variables within a data frame

Usage

counts_df(
  data,
  by,
  id = NULL,
  style = 1,
  ret = "tbl",
  capt = "Information multiple data frames",
  align = NULL,
  size = "\\footnotesize",
  ...
)

Arguments

data

data frame for which the table should be created

by

character identifying by variables within the data frame for stratification

id

character identifying the ID variable within the data frame (see details)

style

numeric with the type of output to return (see details)

ret

a character vector to define what kind of output should be returned (either "dfrm", "tbl", "file")

capt

character with the caption of the table (not used in case data frame is returned)

align

alignment of the table passed to general_tbl (not used in case data frame is returned)

size

character with font size as for the table general_tbl

...

additional arguments passed to general_tbl

Details

This function generates frequency tables, by default for the number of observation per strata. In case the id argument is used the function will also report the number and frequencies of distinct IDs. By default the observations and percentages are reported in separate columns (convenient for further processing). In case style is set to a value of 2, a single column is created that holds the observations and percentages in a formatted ways (convenient for tabulating)

Value

a data frame, code for table or nothing in case a PDF file is created

Author(s)

Richard Hooijmaijers

Examples


data("Theoph")
Theoph$trt <- ifelse(as.numeric(Theoph$Subject)<6,1,2)
Theoph$sex <- ifelse(as.numeric(Theoph$Subject)<4,1,0)
counts_df(data=Theoph, by=c("trt","sex"),id="Subject", ret="dfrm")
counts_df(data=Theoph, by="sex",id="Subject", ret="dfrm")
counts_df(data=Theoph, by=c("trt","sex"),id="Subject", style=2, ret="dfrm")


amp.dm documentation built on March 13, 2026, 5:08 p.m.