GDAtools (version 1.5)

wtable: Computes a (possibly weighted) contingency table

Description

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

Usage

wtable(var1,var2=NULL,w=rep.int(1,length(var1)),digits=0,mar=TRUE,na=TRUE)

Arguments

var1

an object which can be interpreted as factor

var2

an optional object which can be interpreted as factor

w

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

digits

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

mar

logical. If TRUE (default), margins are computed

na

logical. If TRUE (default), 'NA' are treated as a category. If FALSE, they are ignored

Value

Returns a contingency table in matrix format.

See Also

table, prop.wtable

Examples

Run this code
# NOT RUN {
## 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)
# }

Run the code above in your browser using DataLab