\documentclass[12pt]{article} \usepackage{float,graphicx, geometry, amssymb, amsmath, amsfonts, verbatim, latexsym, natbib} \usepackage{Sweave} \bibpunct{(}{)}{;}{a}{,}{,} \geometry{left=1.25in, right=1.25in, top=1in, bottom=1in} \title{Sweave Demo} \author{Houston Gilbert} \begin{document} \maketitle This is my in class demo for the \texttt{Sweave()} package in \textsf{R}. <>= library(xtable) samp1 <- rnorm(10) samp2 <- rnorm(10) samp3 <- rnorm(10) samp4 <- rnorm(10) samps <- cbind(samp1, samp2, samp3, samp4) means <- apply(samps,2,mean) samp.means <- rbind(samps, means) colnames(samp.means) <- c(paste("Sample", 1:4)) dig <- c(0,3,3,3,3) xtable(samp.means, digits=dig, caption="Samples of $n$=10 individuals from $N(0,1)$, together with their respective means.") @ From here, we can go on to put a figure into the document... \begin{figure} \begin{center} <>= ms.fxn <- function(x){ samp <- rnorm(x) mean <- mean(samp) mean } ms <- rep(NA,1000) for(i in 1:1000){ ms[i] <- ms.fxn(10) } hist(ms) @ \caption{This is my histogram for the the mean of 1000 samples of 10 N(0,1) random variables.} \label{fig:hist} \end{center} \end{figure} \end{document}