wtable: Computes a (possibly weighted) contingency table

View source: R/wtable.R

wtableR Documentation

Computes a (possibly weighted) contingency table

Description

Computes a contingency table from one or two vectors, with the possibility of specifying weights.

Usage

wtable(x,y=NULL,weights=rep.int(1,length(x)),stat="freq",
              digits=1,mar=TRUE,na_value=NULL)

Arguments

x

an object which can be interpreted as factor

y

an optional object which can be interpreted as factor

weights

an optional numeric vector of weights (by default, a vector of 1 for uniform weights)

stat

character. Whether to compute a contingenct table ("freq", default, percentages ("prop"), row percentages ("rprop") or column percentages ("cprop").

digits

integer indicating the number of decimal places (default is 1)

mar

logical. If TRUE (default), margins are computed

na_value

character. Name of the level for NA category. If NULL (default), NA values are ignored.

Value

Returns a contingency table.

Author(s)

Nicolas Robette

See Also

table, assoc.twocat

Examples

## Computes a contingency table
## of jazz and age variables
## from the 'Music' example data set
## with or without weights
data(Music)
wtable(Music$Jazz)
wtable(Music$Jazz,Music$Age)

weight <- rep(c(0,0.5,1,1.5,2), length.out=nrow(Music))
wtable(Music$Jazz,w=weight,digits=1)
wtable(Music$Jazz,Music$Age,weight,1)

GDAtools documentation built on March 18, 2022, 5:13 p.m.