Editing CommunityData:Knitr
From CommunityData
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 5: | Line 5: | ||
First, you'd want to create an R script that's organized around every table you want to create in your document. The script should create separate dataframes for every one of them. If your table is going to have rownames, include a vector of rownames in your data frame. | First, you'd want to create an R script that's organized around every table you want to create in your document. The script should create separate dataframes for every one of them. If your table is going to have rownames, include a vector of rownames in your data frame. | ||
Your data frame could look something like this: | |||
summary.stats <- data.frame(cbind( | summary.stats <- data.frame(cbind( | ||
Line 14: | Line 14: | ||
)) | )) | ||
Finally, append each table dataframe to a list (i.e. <code>results$summary.stats <- summary.stats</code>), and save this list as an .Rdata file. | |||
Finally, append each table dataframe to a list (i.e. <code>results$summary.stats <- summary.stats</code>), and save this list as an .Rdata file | |||
== Latex Preamble == | == Latex Preamble == | ||
Line 32: | Line 28: | ||
@ | @ | ||
Now, after your <code>\begin{document}</code> command, import your dataset and necessary R packages. You'll need xtable for generating LaTeX tables from Rdata files and ggplot2 for charts and diagrams. | |||
<<import, echo=FALSE, message=FALSE>>= | <<import, echo=FALSE, message=FALSE>>= | ||
library(xtable) | library(xtable) | ||
library(ggplot2) | library(ggplot2) | ||
bold <- function(x) {paste('{\\textbf{',x,'}}', sep ='')} | bold <- function(x) {paste('{\\textbf{',x,'}}', sep ='')} | ||
gray <- function(x) {paste('{\\textcolor{gray}{',x,'}}', sep ='')} | gray <- function(x) {paste('{\\textcolor{gray}{',x,'}}', sep ='')} | ||
wrapify <- function (x) {paste("{", x, "}", sep="")} | wrapify <- function (x) {paste("{", x, "}", sep="")} | ||
f <- function (x) {formatC(x, format="d", big.mark=',')} | f <- function (x) {formatC(x, format="d", big.mark=',')} | ||
load("my_data.RData") | load("my_data.RData") | ||
attach(results) | attach(results) | ||
@ | @ | ||
== Documentation == | == Documentation == | ||