data(warpbreaks)
# A one-way table
stat.table(tension,list(count(),mean(breaks)),data=warpbreaks)
# The same table with informative labels
stat.table(index=list("Tension level"=tension),list(N=count(),
"mean number of breaks"=mean(breaks)),data=warpbreaks)
# A two-way table
stat.table(index=list(tension,wool),mean(breaks),data=warpbreaks)
# The same table with margins over tension, but not wool
stat.table(index=list(tension,wool),mean(breaks),data=warpbreaks,
margins=c(TRUE, FALSE))
# A table of column percentages
stat.table(list(tension,wool), percent(tension), data=warpbreaks)
# Cell percentages, with margins
stat.table(list(tension,wool),percent(tension,wool), margin=TRUE,
data=warpbreaks)
# A table with multiple statistics
# Note how each statistic has its own default precision
a <- stat.table(index=list(wool,tension),
contents=list(count(),mean(breaks),percent (wool)),
data=warpbreaks)
print(a)
# Print the percentages rounded to the nearest integer
print(a, digits=c(percent=0))
# An Epidemiological example with follow-up time
data(nickel)
str(nickel)
# Make a grouped version of the exposure variable
nickel$egr <- cut( nickel$exposure, breaks=c(0, 0.5, 5, 10, 100), right=FALSE )
stat.table( egr, list( count(), percent(egr), mean( age1st ) ), data=nickel )
# Split the follow-up time by current age
nickel.ex <-
Lexis( entry=agein, exit=ageout, fail=icd %in% c(162,163),
origin=0, breaks=seq(0,100,20),
include=list( id, exposure, egr, age1st, icd ), data=nickel )
str( nickel.ex )
# Table of rates
stat.table( Time, list( n=count(), N=count(id), D=sum(Fail),
"Rate/1000"=ratio(Fail,Exit-Entry,1000) ),
margin=1, data=nickel.ex )
# Two-way table of rates and no. persons contributing
stat.table( list(age=Time, Exposure=egr),
list( N=count(id), D=sum(Fail), Y=sum((Exit-Entry)/1000),
Rate=ratio(Fail,Exit-Entry,1000) ),
margin=TRUE, data=nickel.ex )
Run the code above in your browser using DataLab