tab: Table of frequencies or relative frequencies bordered with...

Description Usage Arguments Value Author(s) Examples

Description

Generates a table of frequencies or relative frequencies or relative percentages

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
tab( df, ~ a + b )

tab( df, ~ a + b , pct = 1)

tab( ~ a + b + c , df, pr = c(1,2))

tab( a, b, c )

tab( a, b, c, weights = w)

tab( w ~ a + b + c, df)

Tab( a, b, c, Weights = w, pct = 1, keep = 1)

Arguments

...

as with table, one or more objects which can be interpreted as factors (including character strings), or a list (or data frame) whose components can be so interpreted.

data

a data frame in which formula are interpreted

fmla

a formula whose right-hand side names the variables to be used for tabulation. The optional left-hand side specifies a variable to be used for weights.

useNA

whether to include NA levels. The default is "ifany". Can also be set to "no" or "always".

pct

margins to be scaled to sum to 100

pr

margins to be scaled to sum to 1

total.margins

if FALSE, generate table without margins

weights

instead of generating a frequency table, generate a table with the sum of the weights

keep

names of margins to keep with 'Tab', default = "All". To drop all margins, use default = "".

Value

An object of class 'table' of dimension equal to the number of variables, with optional margins showing totals. Elements of the matrix can be frequencies, relative frequencies, percentages or sums of weights.

Author(s)

Georges Monette

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
titanic <- as.data.frame(Titanic)
head(titanic)
tab(titanic, ~ Sex + Age, weights = Freq) 

tab(titanic, ~ Sex + Survived + Age, weights = Freq)

round(tab(titanic, ~ Sex + Survived + Age, 
    pct = c(1,3), weights = Freq),2)

round(Tab(titanic, ~ Sex + Survived + Age, 
    pct = c(1,3), weights = Freq),2)

round(Tab(titanic, ~ Sex + Survived + Age, 
    pct = c(1,3), weights = Freq, keep = ""),2)

gmonette/spida15 documentation built on May 17, 2019, 7:26 a.m.