xtab {prettyR} | R Documentation |
Crosstabulates variables with small numbers of unique values.
xtab(formula,data,varnames=NULL,chisq=FALSE,phi=FALSE)
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 |
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
.
The result of calculate.xtab
if there is only one table to display,
otherwise nil.
Jim Lemon
table
, calculate.xtab
, print.xtab
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) # now add some value labels attr(test.df$suburb,"value.labels")<-1:4 names(attr(test.df$suburb,"value.labels"))<- c("Upper","Middle","Working","Slum") attr(test.df$social.type,"value.labels")<-LETTERS[1:4] names(attr(test.df$social.type,"value.labels"))<- c("Gregarious","Mixer","Aloof","Hermit") xtab(sex~suburb+social.type,test.df)