72 lines
1.3 KiB
Plaintext
72 lines
1.3 KiB
Plaintext
% -*- mode: noweb; noweb-default-code-mode: R-mode; -*-
|
|
\documentclass[a4paper]{article}
|
|
|
|
\title{A Test File}
|
|
\author{Friedrich Leisch}
|
|
|
|
\SweaveOpts{echo=FALSE}
|
|
\usepackage{a4wide}
|
|
|
|
\begin{document}
|
|
|
|
\maketitle
|
|
|
|
A simple example: the integers from 1 to 10 are
|
|
<<print=TRUE>>=
|
|
1:10
|
|
<<results=hide>>=
|
|
print(1:20)
|
|
@ % the above is just to ensure that 2 code chunks can follow each other
|
|
|
|
We can also emulate a simple calculator:
|
|
<<echo=TRUE,print=TRUE>>=
|
|
1 + 1
|
|
1 + pi
|
|
sin(pi/2)
|
|
@
|
|
|
|
Now we look at Gaussian data:
|
|
|
|
<<>>=
|
|
library(stats)
|
|
x <- rnorm(20)
|
|
print(x)
|
|
print(t1 <- t.test(x))
|
|
@
|
|
Note that we can easily integrate some numbers into standard text: The
|
|
third element of vector \texttt{x} is \Sexpr{x[3]}, the
|
|
$p$-value of the test is \Sexpr{format.pval(t1$p.value)}. % $
|
|
|
|
Now we look at a summary of the famous \texttt{iris} data set, and we
|
|
want to see the commands in the code chunks:
|
|
|
|
\SweaveOpts{echo=true}
|
|
|
|
<<>>=
|
|
data(iris)
|
|
summary(iris)
|
|
@ %def
|
|
|
|
|
|
\begin{figure}[htbp]
|
|
\begin{center}
|
|
<<fig=TRUE>>=
|
|
library(graphics)
|
|
pairs(iris)
|
|
@
|
|
\caption{Pairs plot of the iris data.}
|
|
\end{center}
|
|
\end{figure}
|
|
|
|
\begin{figure}[htbp]
|
|
\begin{center}
|
|
<<fig=true>>=
|
|
boxplot(Sepal.Length~Species, data=iris)
|
|
@
|
|
\caption{Boxplot of sepal length grouped by species.}
|
|
\end{center}
|
|
\end{figure}
|
|
@
|
|
|
|
\end{document}
|