Learn R Programming

prettyR (version 1.0-4)

xtab: Crosstabulate variables

Description

Crosstabulates variables with small numbers of unique values.

Usage

xtab(formula,data,varnames=NULL,chisq=FALSE,phi=FALSE)

Arguments

formula
a formula containing the variables to be crosstabulated
data
the data frame from which to select the variables
varnames
optional labels for the variables (defaults to names(data))
chisq
logical - whether to display chi squared test(s) of the table(s)
phi
whether to calculate and display the phi coefficient of association - only for 2x2 tables

Value

  • The result of calculate.xtab if there is only one table to display, otherwise nil.

Details

xtab will accept a formula referring to columns in a data frame or two explicit variable names. It calls calculate.xtab for the calculations and displays one or more tables of results by calling print.xtab.

See Also

table, calculate.xtab, print.xtab

Examples

Run this code
test.df<-data.frame(sex=sample(c("MALE","FEMALE"),1000,TRUE),
 suburb=sample(1:4,1000,TRUE),social.type=sample(LETTERS[1:4],1000,TRUE))
 xtab(sex~suburb+social.type,test.df,chisq=TRUE)

Run the code above in your browser using DataLab