R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("xtable-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('xtable') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "xtable" > > ### * xtable > > flush(stderr()); flush(stdout()) > > ### Name: xtable > ### Title: Create Export Tables > ### Aliases: xtable xtable.anova xtable.aov xtable.aovlist > ### xtable.data.frame xtable.glm xtable.lm xtable.matrix xtable.prcomp > ### xtable.coxph xtable.summary.aov xtable.summary.aovlist > ### xtable.summary.glm xtable.summary.lm xtable.summary.prcomp xtable.ts > ### Keywords: file > > ### ** Examples > > > ## Load example dataset > data(tli) > > ## Demonstrate data.frame > tli.table <- xtable(tli[1:20,]) > digits(tli.table)[c(2,6)] <- 0 > print(tli.table) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:07 2005 \begin{table}[ht] \begin{center} \begin{tabular}{rrlllr} \hline & grade & sex & disadvg & ethnicty & tlimth \\ \hline 1 & 6 & M & YES & HISPANIC & 43 \\ 2 & 7 & M & NO & BLACK & 88 \\ 3 & 5 & F & YES & HISPANIC & 34 \\ 4 & 3 & M & YES & HISPANIC & 65 \\ 5 & 8 & M & YES & WHITE & 75 \\ 6 & 5 & M & NO & BLACK & 74 \\ 7 & 8 & F & YES & HISPANIC & 72 \\ 8 & 4 & M & YES & BLACK & 79 \\ 9 & 6 & M & NO & WHITE & 88 \\ 10 & 7 & M & YES & HISPANIC & 87 \\ 11 & 3 & M & NO & WHITE & 79 \\ 12 & 6 & F & NO & WHITE & 84 \\ 13 & 8 & M & NO & WHITE & 90 \\ 14 & 5 & M & NO & WHITE & 73 \\ 15 & 8 & F & NO & WHITE & 72 \\ 16 & 6 & F & NO & BLACK & 82 \\ 17 & 4 & M & NO & WHITE & 69 \\ 18 & 3 & F & YES & HISPANIC & 17 \\ 19 & 3 & M & NO & HISPANIC & 37 \\ 20 & 5 & M & NO & WHITE & 70 \\ \hline \end{tabular} \end{center} \end{table} > print(tli.table,type="html")
grade sex disadvg ethnicty tlimth
1 6 M YES HISPANIC 43
2 7 M NO BLACK 88
3 5 F YES HISPANIC 34
4 3 M YES HISPANIC 65
5 8 M YES WHITE 75
6 5 M NO BLACK 74
7 8 F YES HISPANIC 72
8 4 M YES BLACK 79
9 6 M NO WHITE 88
10 7 M YES HISPANIC 87
11 3 M NO WHITE 79
12 6 F NO WHITE 84
13 8 M NO WHITE 90
14 5 M NO WHITE 73
15 8 F NO WHITE 72
16 6 F NO BLACK 82
17 4 M NO WHITE 69
18 3 F YES HISPANIC 17
19 3 M NO HISPANIC 37
20 5 M NO WHITE 70
> > ## Demonstrate matrix > design.matrix <- model.matrix(~ sex*grade, data=tli[1:20,]) > design.table <- xtable(design.matrix) > print(design.table) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:07 2005 \begin{table}[ht] \begin{center} \begin{tabular}{rrrrr} \hline & (Intercept) & sexM & grade & sexM:grade \\ \hline 1 & 1.00 & 1.00 & 6.00 & 6.00 \\ 2 & 1.00 & 1.00 & 7.00 & 7.00 \\ 3 & 1.00 & 0.00 & 5.00 & 0.00 \\ 4 & 1.00 & 1.00 & 3.00 & 3.00 \\ 5 & 1.00 & 1.00 & 8.00 & 8.00 \\ 6 & 1.00 & 1.00 & 5.00 & 5.00 \\ 7 & 1.00 & 0.00 & 8.00 & 0.00 \\ 8 & 1.00 & 1.00 & 4.00 & 4.00 \\ 9 & 1.00 & 1.00 & 6.00 & 6.00 \\ 10 & 1.00 & 1.00 & 7.00 & 7.00 \\ 11 & 1.00 & 1.00 & 3.00 & 3.00 \\ 12 & 1.00 & 0.00 & 6.00 & 0.00 \\ 13 & 1.00 & 1.00 & 8.00 & 8.00 \\ 14 & 1.00 & 1.00 & 5.00 & 5.00 \\ 15 & 1.00 & 0.00 & 8.00 & 0.00 \\ 16 & 1.00 & 0.00 & 6.00 & 0.00 \\ 17 & 1.00 & 1.00 & 4.00 & 4.00 \\ 18 & 1.00 & 0.00 & 3.00 & 0.00 \\ 19 & 1.00 & 1.00 & 3.00 & 3.00 \\ 20 & 1.00 & 1.00 & 5.00 & 5.00 \\ \hline \end{tabular} \end{center} \end{table} > print(design.table,type="html")
(Intercept) sexM grade sexM:grade
1 1.00 1.00 6.00 6.00
2 1.00 1.00 7.00 7.00
3 1.00 0.00 5.00 0.00
4 1.00 1.00 3.00 3.00
5 1.00 1.00 8.00 8.00
6 1.00 1.00 5.00 5.00
7 1.00 0.00 8.00 0.00
8 1.00 1.00 4.00 4.00
9 1.00 1.00 6.00 6.00
10 1.00 1.00 7.00 7.00
11 1.00 1.00 3.00 3.00
12 1.00 0.00 6.00 0.00
13 1.00 1.00 8.00 8.00
14 1.00 1.00 5.00 5.00
15 1.00 0.00 8.00 0.00
16 1.00 0.00 6.00 0.00
17 1.00 1.00 4.00 4.00
18 1.00 0.00 3.00 0.00
19 1.00 1.00 3.00 3.00
20 1.00 1.00 5.00 5.00
> > ## Demonstrate aov > fm1 <- aov(tlimth ~ sex + ethnicty + grade + disadvg, data=tli) > fm1.table <- xtable(fm1) > print(fm1.table) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:07 2005 \begin{table}[ht] \begin{center} \begin{tabular}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr($>$F) \\ \hline sex & 1 & 75.37 & 75.37 & 0.38 & 0.5417 \\ ethnicty & 3 & 2572.15 & 857.38 & 4.27 & 0.0072 \\ grade & 1 & 36.31 & 36.31 & 0.18 & 0.6717 \\ disadvg & 1 & 59.30 & 59.30 & 0.30 & 0.5882 \\ Residuals & 93 & 18682.87 & 200.89 & & \\ \hline \end{tabular} \end{center} \end{table} > print(fm1.table,type="html")
Df Sum Sq Mean Sq F value Pr(> F)
sex 1 75.37 75.37 0.38 0.5417
ethnicty 3 2572.15 857.38 4.27 0.0072
grade 1 36.31 36.31 0.18 0.6717
disadvg 1 59.30 59.30 0.30 0.5882
Residuals 93 18682.87 200.89
> > ## Demonstrate lm > fm2 <- lm(tlimth ~ sex*ethnicty, data=tli) > fm2.table <- xtable(fm2) > print(fm2.table) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:07 2005 \begin{table}[ht] \begin{center} \begin{tabular}{rrrrr} \hline & Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\ \hline (Intercept) & 73.6364 & 4.2502 & 17.33 & 0.0000 \\ sexM & $-$1.6364 & 5.8842 & $-$0.28 & 0.7816 \\ ethnictyHISPANIC & $-$9.7614 & 6.5501 & $-$1.49 & 0.1395 \\ ethnictyOTHER & 15.8636 & 10.8360 & 1.46 & 0.1466 \\ ethnictyWHITE & 4.7970 & 4.9687 & 0.97 & 0.3368 \\ sexM:ethnictyHISPANIC & 10.6780 & 8.7190 & 1.22 & 0.2238 \\ sexM:ethnictyWHITE & 5.1230 & 7.0140 & 0.73 & 0.4670 \\ \hline \end{tabular} \end{center} \end{table} > print(fm2.table,type="html")
Estimate Std. Error t value Pr(> |t|)
(Intercept) 73.6364 4.2502 17.33 0.0000
sexM -1.6364 5.8842 -0.28 0.7816
ethnictyHISPANIC -9.7614 6.5501 -1.49 0.1395
ethnictyOTHER 15.8636 10.8360 1.46 0.1466
ethnictyWHITE 4.7970 4.9687 0.97 0.3368
sexM:ethnictyHISPANIC 10.6780 8.7190 1.22 0.2238
sexM:ethnictyWHITE 5.1230 7.0140 0.73 0.4670
> print(xtable(anova(fm2))) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:07 2005 \begin{table}[ht] \begin{center} \begin{tabular}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr($>$F) \\ \hline sex & 1 & 75.37 & 75.37 & 0.38 & 0.5395 \\ ethnicty & 3 & 2572.15 & 857.38 & 4.31 & 0.0068 \\ sex:ethnicty & 2 & 298.43 & 149.22 & 0.75 & 0.4748 \\ Residuals & 93 & 18480.04 & 198.71 & & \\ \hline \end{tabular} \end{center} \end{table} > print(xtable(anova(fm2)),type="html")
Df Sum Sq Mean Sq F value Pr(> F)
sex 1 75.37 75.37 0.38 0.5395
ethnicty 3 2572.15 857.38 4.31 0.0068
sex:ethnicty 2 298.43 149.22 0.75 0.4748
Residuals 93 18480.04 198.71
> fm2b <- lm(tlimth ~ ethnicty, data=tli) > print(xtable(anova(fm2b,fm2))) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:07 2005 \begin{table}[ht] \begin{center} \begin{tabular}{lrrrrrr} \hline & Res.Df & RSS & Df & Sum of Sq & F & Pr($>$F) \\ \hline 1 & 96 & 19053.59 & & & & \\ 2 & 93 & 18480.04 & 3 & 573.55 & 0.96 & 0.4141 \\ \hline \end{tabular} \end{center} \end{table} > print(xtable(anova(fm2b,fm2)),type="html")
Res.Df RSS Df Sum of Sq F Pr(> F)
1 96 19053.59
2 93 18480.04 3 573.55 0.96 0.4141
> > ## Demonstrate glm > fm3 <- glm(disadvg ~ ethnicty*grade, data=tli, family=binomial()) > fm3.table <- xtable(fm3) > print(fm3.table) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:07 2005 \begin{table}[ht] \begin{center} \begin{tabular}{rrrrr} \hline & Estimate & Std. Error & z value & Pr($>$$|$z$|$) \\ \hline (Intercept) & 3.1888 & 1.5966 & 2.00 & 0.0458 \\ ethnictyHISPANIC & $-$0.2848 & 2.4808 & $-$0.11 & 0.9086 \\ ethnictyOTHER & 212.1701 & 22122.7093 & 0.01 & 0.9923 \\ ethnictyWHITE & $-$8.8150 & 3.3355 & $-$2.64 & 0.0082 \\ grade & $-$0.5308 & 0.2892 & $-$1.84 & 0.0665 \\ ethnictyHISPANIC:grade & 0.2448 & 0.4357 & 0.56 & 0.5742 \\ ethnictyOTHER:grade & $-$32.6014 & 3393.4687 & $-$0.01 & 0.9923 \\ ethnictyWHITE:grade & 1.0171 & 0.5185 & 1.96 & 0.0498 \\ \hline \end{tabular} \end{center} \end{table} > print(fm3.table,type="html")
Estimate Std. Error z value Pr(> |z|)
(Intercept) 3.1888 1.5966 2.00 0.0458
ethnictyHISPANIC -0.2848 2.4808 -0.11 0.9086
ethnictyOTHER 212.1701 22122.7093 0.01 0.9923
ethnictyWHITE -8.8150 3.3355 -2.64 0.0082
grade -0.5308 0.2892 -1.84 0.0665
ethnictyHISPANIC:grade 0.2448 0.4357 0.56 0.5742
ethnictyOTHER:grade -32.6014 3393.4687 -0.01 0.9923
ethnictyWHITE:grade 1.0171 0.5185 1.96 0.0498
> print(xtable(anova(fm3))) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:07 2005 \begin{table}[ht] \begin{center} \begin{tabular}{lrrrr} \hline & Df & Deviance & Resid. Df & Resid. Dev \\ \hline NULL & & & 99 & 129.49 \\ ethnicty & 3 & 47.24 & 96 & 82.25 \\ grade & 1 & 1.73 & 95 & 80.52 \\ ethnicty:grade & 3 & 7.20 & 92 & 73.32 \\ \hline \end{tabular} \end{center} \end{table} > print(xtable(anova(fm3)),type="html")
Df Deviance Resid. Df Resid. Dev
NULL 99 129.49
ethnicty 3 47.24 96 82.25
grade 1 1.73 95 80.52
ethnicty:grade 3 7.20 92 73.32
> > ## Demonstrate aov > ## Taken from help(aov) in R 1.1.1 > ## From Venables and Ripley (1997) p.210. > N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0) > P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0) > K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0) > yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,55.0, + 62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0) > npk <- data.frame(block=gl(6,4), N=factor(N), P=factor(P), K=factor(K), yield=yield) > npk.aov <- aov(yield ~ block + N*P*K, npk) > op <- options(contrasts=c("contr.helmert", "contr.treatment")) > npk.aovE <- aov(yield ~ N*P*K + Error(block), npk) > options(op) > > summary(npk.aov) Df Sum Sq Mean Sq F value Pr(>F) block 5 343.30 68.66 4.4467 0.015939 * N 1 189.28 189.28 12.2587 0.004372 ** P 1 8.40 8.40 0.5441 0.474904 K 1 95.20 95.20 6.1657 0.028795 * N:P 1 21.28 21.28 1.3783 0.263165 N:K 1 33.14 33.14 2.1460 0.168648 P:K 1 0.48 0.48 0.0312 0.862752 Residuals 12 185.29 15.44 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > print(xtable(npk.aov)) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:07 2005 \begin{table}[ht] \begin{center} \begin{tabular}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr($>$F) \\ \hline block & 5 & 343.30 & 68.66 & 4.45 & 0.0159 \\ N & 1 & 189.28 & 189.28 & 12.26 & 0.0044 \\ P & 1 & 8.40 & 8.40 & 0.54 & 0.4749 \\ K & 1 & 95.20 & 95.20 & 6.17 & 0.0288 \\ N:P & 1 & 21.28 & 21.28 & 1.38 & 0.2632 \\ N:K & 1 & 33.14 & 33.14 & 2.15 & 0.1686 \\ P:K & 1 & 0.48 & 0.48 & 0.03 & 0.8628 \\ Residuals & 12 & 185.29 & 15.44 & & \\ \hline \end{tabular} \end{center} \end{table} > print(xtable(anova(npk.aov))) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:08 2005 \begin{table}[ht] \begin{center} \begin{tabular}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr($>$F) \\ \hline block & 5 & 343.30 & 68.66 & 4.45 & 0.0159 \\ N & 1 & 189.28 & 189.28 & 12.26 & 0.0044 \\ P & 1 & 8.40 & 8.40 & 0.54 & 0.4749 \\ K & 1 & 95.20 & 95.20 & 6.17 & 0.0288 \\ N:P & 1 & 21.28 & 21.28 & 1.38 & 0.2632 \\ N:K & 1 & 33.14 & 33.14 & 2.15 & 0.1686 \\ P:K & 1 & 0.48 & 0.48 & 0.03 & 0.8628 \\ Residuals & 12 & 185.29 & 15.44 & & \\ \hline \end{tabular} \end{center} \end{table} > print(xtable(summary(npk.aov))) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:08 2005 \begin{table}[ht] \begin{center} \begin{tabular}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr($>$F) \\ \hline block & 5 & 343.30 & 68.66 & 4.45 & 0.0159 \\ N & 1 & 189.28 & 189.28 & 12.26 & 0.0044 \\ P & 1 & 8.40 & 8.40 & 0.54 & 0.4749 \\ K & 1 & 95.20 & 95.20 & 6.17 & 0.0288 \\ N:P & 1 & 21.28 & 21.28 & 1.38 & 0.2632 \\ N:K & 1 & 33.14 & 33.14 & 2.15 & 0.1686 \\ P:K & 1 & 0.48 & 0.48 & 0.03 & 0.8628 \\ Residuals & 12 & 185.29 & 15.44 & & \\ \hline \end{tabular} \end{center} \end{table} > > summary(npk.aovE) Error: block Df Sum Sq Mean Sq F value Pr(>F) N:P:K 1 37.002 37.002 0.4832 0.5252 Residuals 4 306.293 76.573 Error: Within Df Sum Sq Mean Sq F value Pr(>F) N 1 189.282 189.282 12.2587 0.004372 ** P 1 8.402 8.402 0.5441 0.474904 K 1 95.202 95.202 6.1657 0.028795 * N:P 1 21.282 21.282 1.3783 0.263165 N:K 1 33.135 33.135 2.1460 0.168648 P:K 1 0.482 0.482 0.0312 0.862752 Residuals 12 185.287 15.441 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > print(xtable(npk.aovE),type="html")
Df Sum Sq Mean Sq F value Pr(> F)
N:P:K 1 37.00 37.00 0.48 0.5252
Residuals 4 306.29 76.57
N 1 189.28 189.28 12.26 0.0044
P 1 8.40 8.40 0.54 0.4749
K 1 95.20 95.20 6.17 0.0288
N:P 1 21.28 21.28 1.38 0.2632
N:K 1 33.14 33.14 2.15 0.1686
P:K 1 0.48 0.48 0.03 0.8628
Residuals1 12 185.29 15.44
> print(xtable(summary(npk.aovE)),type="html")
Df Sum Sq Mean Sq F value Pr(> F)
N:P:K 1 37.00 37.00 0.48 0.5252
Residuals 4 306.29 76.57
N 1 189.28 189.28 12.26 0.0044
P 1 8.40 8.40 0.54 0.4749
K 1 95.20 95.20 6.17 0.0288
N:P 1 21.28 21.28 1.38 0.2632
N:K 1 33.14 33.14 2.15 0.1686
P:K 1 0.48 0.48 0.03 0.8628
Residuals1 12 185.29 15.44
> > ## Demonstrate lm > ## Taken from help(lm) in R 1.1.1 > ## Annette Dobson (1990) "An Introduction to Generalized Linear Models". > ## Page 9: Plant Weight Data. > ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) > trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) > group <- gl(2,10,20, labels=c("Ctl","Trt")) > weight <- c(ctl, trt) > lm.D9 <- lm(weight ~ group) > print(xtable(lm.D9)) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:08 2005 \begin{table}[ht] \begin{center} \begin{tabular}{rrrrr} \hline & Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\ \hline (Intercept) & 5.0320 & 0.2202 & 22.85 & 0.0000 \\ groupTrt & $-$0.3710 & 0.3114 & $-$1.19 & 0.2490 \\ \hline \end{tabular} \end{center} \end{table} > print(xtable(anova(lm.D9))) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:08 2005 \begin{table}[ht] \begin{center} \begin{tabular}{lrrrrr} \hline & Df & Sum Sq & Mean Sq & F value & Pr($>$F) \\ \hline group & 1 & 0.69 & 0.69 & 1.42 & 0.2490 \\ Residuals & 18 & 8.73 & 0.48 & & \\ \hline \end{tabular} \end{center} \end{table} > > ## Demonstrate glm > ## Taken from help(glm) in R 1.1.1 > ## Annette Dobson (1990) "An Introduction to Generalized Linear Models". > ## Page 93: Randomized Controlled Trial : > counts <- c(18,17,15,20,10,20,25,13,12) > outcome <- gl(3,1,9) > treatment <- gl(3,3) > d.AD <- data.frame(treatment, outcome, counts) > glm.D93 <- glm(counts ~ outcome + treatment, family=poisson()) > print(xtable(glm.D93,align="r|llrc")) % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:08 2005 \begin{table}[ht] \begin{center} \begin{tabular}{r|llrc} \hline & Estimate & Std. Error & z value & Pr($>$$|$z$|$) \\ \hline (Intercept) & 3.0445 & 0.1709 & 17.81 & 0.0000 \\ outcome2 & $-$0.4543 & 0.2022 & $-$2.25 & 0.0246 \\ outcome3 & $-$0.2930 & 0.1927 & $-$1.52 & 0.1285 \\ treatment2 & $-$0.0000 & 0.2000 & $-$0.00 & 1.0000 \\ treatment3 & $-$0.0000 & 0.2000 & $-$0.00 & 1.0000 \\ \hline \end{tabular} \end{center} \end{table} > print(xtable(anova(glm.D93)),hline.after=c(1),size="small") % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:08 2005 \begin{table}[ht] \begin{center} {\small \begin{tabular}{lrrrr} \hline & Df & Deviance & Resid. Df & Resid. Dev \\ \hline NULL & & & 8 & 10.58 \\ \hline outcome & 2 & 5.45 & 6 & 5.13 \\ treatment & 2 & 0.00 & 4 & 5.13 \\ \hline \end{tabular} } \end{center} \end{table} > > if(require(stats,quietly=TRUE)) { + ## Demonstrate prcomp + ## Taken from help(prcomp) in mva package of R 1.1.1 + data(USArrests) + pr1 <- prcomp(USArrests) + print(xtable(pr1)) + print(xtable(summary(pr1))) + + # ## Demonstrate princomp + # ## Taken from help(princomp) in mva package of R 1.1.1 + # pr2 <- princomp(USArrests) + # print(xtable(pr2)) + } % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:08 2005 \begin{table}[ht] \begin{center} \begin{tabular}{rrrrr} \hline & PC1 & PC2 & PC3 & PC4 \\ \hline Murder & 0.0417 & $-$0.0448 & 0.0799 & $-$0.9949 \\ Assault & 0.9952 & $-$0.0588 & $-$0.0676 & 0.0389 \\ UrbanPop & 0.0463 & 0.9769 & $-$0.2005 & $-$0.0582 \\ Rape & 0.0752 & 0.2007 & 0.9741 & 0.0723 \\ \hline \end{tabular} \end{center} \end{table} % latex table generated in R 2.1.1 by xtable 1.2-5 package % Wed Jul 13 20:41:08 2005 \begin{table}[ht] \begin{center} \begin{tabular}{rrrrr} \hline & PC1 & PC2 & PC3 & PC4 \\ \hline Standard deviation & 83.7324 & 14.2124 & 6.4894 & 2.4828 \\ Proportion of Variance & 0.9655 & 0.0278 & 0.0058 & 0.0008 \\ Cumulative Proportion & 0.9655 & 0.9933 & 0.9991 & 1.0000 \\ \hline \end{tabular} \end{center} \end{table} > > ## Don't show: > for(i in c("latex","html")) { + outFileName = paste("xtable.",ifelse(i=="latex","tex",i),sep="") + print(tli.table,type=i,file=outFileName,append=FALSE) + print(design.table,type=i,file=outFileName,append=TRUE) + print(fm1.table,type=i,file=outFileName,append=TRUE) + print(fm2.table,type=i,file=outFileName,append=TRUE) + print(xtable(anova(fm2)),type=i,file=outFileName,append=TRUE) + print(xtable(anova(fm2b,fm2)),type=i,file=outFileName,append=TRUE) + print(fm3.table,type=i,file=outFileName,append=TRUE) + print(xtable(anova(fm3)),type=i,file=outFileName,append=TRUE) + print(xtable(npk.aov),type=i,file=outFileName,append=TRUE) + print(xtable(anova(npk.aov)),type=i,file=outFileName,append=TRUE) + print(xtable(summary(npk.aov)),type=i,file=outFileName,append=TRUE) + print(xtable(npk.aovE),type=i,file=outFileName,append=TRUE) + print(xtable(summary(npk.aovE)),type=i,file=outFileName,append=TRUE) + if(i=="latex") cat("\\clearpage\n",file=outFileName,append=TRUE) + print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environment=NULL) + print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environment="") + print(xtable(lm.D9),type=i,file=outFileName,append=TRUE,latex.environment="center") + print(xtable(anova(lm.D9)),type=i,file=outFileName,append=TRUE) + print(xtable(glm.D93),type=i,file=outFileName,append=TRUE) + print(xtable(anova(glm.D93,test="Chisq")),type=i,file=outFileName,append=TRUE) + print(xtable(glm.D93,align="r|llrc"),type=i,file=outFileName,append=TRUE) + print(xtable(anova(glm.D93)),hline.after=c(1),size="small",type=i,file=outFileName,append=TRUE) + if(require(stats,quietly=TRUE)) { + print(xtable(pr1),type=i,file=outFileName,append=TRUE) + print(xtable(summary(pr1)),type=i,file=outFileName,append=TRUE) + # print(xtable(pr2),type=i,file=outFileName,append=TRUE) + } + temp.table <- xtable(ts(cumsum(1+round(rnorm(100), 2)), start = c(1954, 7), frequency=12)) + caption(temp.table) <- "Time series example" + print(temp.table,type=i,file=outFileName,append=TRUE,caption.placement="top",table.placement="h") + print(temp.table,type=i,file=outFileName,append=TRUE,caption.placement="bottom",table.placement="htb") + } Warning: data length [6] is not a sub-multiple or multiple of the number of rows [5] in matrix > ## End Don't show > > > > > options(contrasts = c(unordered = "contr.treatment",ordered = "contr.poly")) > ### *