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

xtab

Crosstabulations using formula


Description

Functions to create contingency table using formula

Usage

xtab(formula, data, useNA = FALSE, exclude = c(NA,NaN), miss.char = "-",
     na.action = na.exclude, subset = NULL, sparse = FALSE,
     drop.unused.levels = FALSE)
Total(x)

Arguments

formula

Object of class cross to be printed

data

data frame to use with formula

useNA

logical values to add NA to the levels in the table

exclude

levels to exclude from table

miss.char

Character to replace NA

na.action

methods to deal with NA

subset

subset to use in data

sparse

see help(xtabs) for details

drop.unused.levels

logical values indicating whether we drop empty levels

x

numerical vector

Details

The xtab functions corrects the inability to deal with missing values in the original xtabs that comes with R base. Total is a utility function to use in conjunction with addmargins instead of sum.

Value

xtab returns an object of type table (see details). Total returns a sum with na.rm=TRUE by default and replaces NA with 0.

Author(s)

Charles-Édouard Giguère

Examples

require(CUFF)
### example of crosstabs
xtab( ~ N + P, npk)

CUFF

Charles's Utility Function using Formula

v1.7
GPL (>= 2)
Authors
Charles-Édouard Giguère
Initial release
2020-09-16

We don't support your browser anymore

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