wtable: Computes a (possibly weighted) contingency table

Description Usage Arguments Value Author(s) See Also Examples

View source: R/wtable.R

Description

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

Usage

1
2
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## 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)

Example output

    [,1]
No   417
Yes   80
NA     3
tot  500
    15-24 25-49 50+ NA tot
No     65   169 183  0 417
Yes    11    30  39  0  80
NA      0     2   1  0   3
tot    76   201 223  0 500
     [,1]
No  417.5
Yes  79.5
NA    3.0
tot 500.0
    15-24 25-49   50+ NA   tot
No     65 157.5 195.0  0 417.5
Yes    12  34.0  33.5  0  79.5
NA      0   1.0   2.0  0   3.0
tot    77 192.5 230.5  0 500.0

GDAtools documentation built on May 31, 2021, 5:08 p.m.