| 1 |
## ----echo=FALSE,message=FALSE------------------------------------------------- |
| 2 |
knitr::opts_chunk$set(comment=NA, |
| 3 |
fig.align="center", |
| 4 |
results="markup") |
| 5 |
|
| 6 |
## ----------------------------------------------------------------------------- |
| 7 |
tab.Class.Age <- xtabs(Freq~Class+Age,data=Titanic) |
| 8 |
tab.Survived.Class.Age <- xtabs(Freq~Survived+Class+Age,data=Titanic) |
| 9 |
tab.Survived.Class.Sex <- xtabs(Freq~Survived+Class+Sex,data=Titanic) |
| 10 |
tab.Survived.Class <- xtabs(Freq~Survived+Class,data=Titanic) |
| 11 |
tab.Survived.Sex <- xtabs(Freq~Survived+Sex,data=Titanic) |
| 12 |
tab.Survived.Age <- xtabs(Freq~Survived+Age,data=Titanic) |
| 13 |
tab.Survived <- xtabs(Freq~Survived,data=Titanic) |
| 14 |
|
| 15 |
## ----message=FALSE------------------------------------------------------------ |
| 16 |
library(memisc) |
| 17 |
|
| 18 |
## ----------------------------------------------------------------------------- |
| 19 |
(ftab.Survived.Age <- ftable(tab.Survived.Age)) |
| 20 |
(ftab.Survived.Sex <- ftable(tab.Survived.Sex)) |
| 21 |
|
| 22 |
## ----------------------------------------------------------------------------- |
| 23 |
cbind(ftab.Survived.Age, |
| 24 |
ftab.Survived.Sex) |
| 25 |
|
| 26 |
## ----------------------------------------------------------------------------- |
| 27 |
cbind(ftab.Survived.Age, |
| 28 |
ftab.Survived.Sex, |
| 29 |
Total=tab.Survived) |
| 30 |
|
| 31 |
## ----results='asis'----------------------------------------------------------- |
| 32 |
show_html(ftab.Survived.Age) |
| 33 |
|
| 34 |
## ----results='asis'----------------------------------------------------------- |
| 35 |
show_html(ftab.Survived.Sex) |
| 36 |
|
| 37 |
## ----results='asis'----------------------------------------------------------- |
| 38 |
show_html( |
| 39 |
cbind(ftab.Survived.Age, |
| 40 |
ftab.Survived.Sex, |
| 41 |
Total=tab.Survived) |
| 42 |
) |
| 43 |
|
| 44 |
## ----------------------------------------------------------------------------- |
| 45 |
knit_print.ftable_matrix <-function(x,options,...) |
| 46 |
knitr::asis_output( |
| 47 |
format_html(x, |
| 48 |
digits=if(length(options$ftable.digits)) |
| 49 |
options$ftable.digits |
| 50 |
else 0, |
| 51 |
...)) |
| 52 |
|
| 53 |
## ----------------------------------------------------------------------------- |
| 54 |
cbind(ftab.Survived.Age, |
| 55 |
ftab.Survived.Sex, |
| 56 |
Total=tab.Survived) |
| 57 |
|
| 58 |
## ----------------------------------------------------------------------------- |
| 59 |
rm(knit_print.ftable_matrix) |
| 60 |
|
| 61 |
## ----results='asis'----------------------------------------------------------- |
| 62 |
show_html( |
| 63 |
cbind(ftab.Survived.Age, |
| 64 |
ftab.Survived.Sex, |
| 65 |
Total=tab.Survived), |
| 66 |
varinfront=FALSE |
| 67 |
) |
| 68 |
|
| 69 |
## ----results='asis'----------------------------------------------------------- |
| 70 |
show_html( |
| 71 |
cbind(ftab.Survived.Age, |
| 72 |
ftab.Survived.Sex, |
| 73 |
Total=tab.Survived), |
| 74 |
varontop=FALSE |
| 75 |
) |
| 76 |
|
| 77 |
## ----------------------------------------------------------------------------- |
| 78 |
ftab.Age.Survived <- ftable(tab.Survived.Age,col.vars=1) |
| 79 |
ftab.Sex.Survived <- ftable(tab.Survived.Sex,col.vars=1) |
| 80 |
ftab.Class.Survived <- ftable(tab.Survived.Class,col.vars=1) |
| 81 |
|
| 82 |
rbind( |
| 83 |
ftab.Age.Survived, |
| 84 |
ftab.Sex.Survived, |
| 85 |
ftab.Class.Survived, |
| 86 |
Total=tab.Survived |
| 87 |
) |
| 88 |
|
| 89 |
## ----results='asis'----------------------------------------------------------- |
| 90 |
show_html( |
| 91 |
rbind( |
| 92 |
ftab.Age.Survived, |
| 93 |
ftab.Sex.Survived, |
| 94 |
ftab.Class.Survived, |
| 95 |
Total=tab.Survived |
| 96 |
) |
| 97 |
) |
| 98 |
|
| 99 |
## ----results='asis'----------------------------------------------------------- |
| 100 |
ptab.Survived.Age<-percentages(Survived~Age,data=Titanic) |
| 101 |
ptab.Survived.Sex<-percentages(Survived~Sex,data=Titanic) |
| 102 |
ptab.Survived.Class<-percentages(Survived~Class,data=Titanic) |
| 103 |
|
| 104 |
fptab.Age.Survived <- ftable(ptab.Survived.Age,col.vars=1) |
| 105 |
fptab.Sex.Survived <- ftable(ptab.Survived.Sex,col.vars=1) |
| 106 |
fptab.Class.Survived <- ftable(ptab.Survived.Class,col.vars=1) |
| 107 |
|
| 108 |
show_html( |
| 109 |
rbind( |
| 110 |
fptab.Age.Survived, |
| 111 |
fptab.Sex.Survived, |
| 112 |
fptab.Class.Survived |
| 113 |
), |
| 114 |
digits=1 |
| 115 |
) |
| 116 |
|
| 117 |
## ----results='asis'----------------------------------------------------------- |
| 118 |
tab.Age <- xtabs(Freq~Age,data=Titanic) |
| 119 |
tab.Sex <- xtabs(Freq~Sex,data=Titanic) |
| 120 |
tab.Class <- xtabs(Freq~Class,data=Titanic) |
| 121 |
|
| 122 |
|
| 123 |
show_html( |
| 124 |
rbind( |
| 125 |
cbind(fptab.Age.Survived,Total=tab.Age), |
| 126 |
cbind(fptab.Sex.Survived,Total=tab.Sex), |
| 127 |
cbind(fptab.Class.Survived,Total=tab.Class) |
| 128 |
), |
| 129 |
digits=c(1,0) # One digit after dot for percentages |
| 130 |
# no digits for total counts. |
| 131 |
) |
| 132 |
|
| 133 |
## ----------------------------------------------------------------------------- |
| 134 |
toLatex( |
| 135 |
rbind( |
| 136 |
cbind(fptab.Age.Survived,Total=tab.Age), |
| 137 |
cbind(fptab.Sex.Survived,Total=tab.Sex), |
| 138 |
cbind(fptab.Class.Survived,Total=tab.Class) |
| 139 |
), |
| 140 |
digits=c(1,0) # One digit after dot for percentages |
| 141 |
# no digits for total counts. |
| 142 |
) |
| 143 |
|