R markdownis a particular kind of markdown document. Authors should be cautious about following formatting advice for other types of markdown when working on R markdown. The distinguishing feature of R markdownis that it cooperates with R. Like LATEX with Sweave, code chunks can be included. When the document is compiled, the code is executed. An R Markdown document is written in markdown, an easy-to-write plain text format with the file extension.Rmd. It can contain chunks of embedded R code. It has a number of great features: easy syntax for a number of basic objects.
Stargazer and R Markdown to LaTeX |
If you're using LaTeX, then use the Sweave-like knitr opions here instead. The `results='asis'` means that knitr won't do any processing on the output, so when you run this it produces a bunch of gobbledygook. |
```{r} |
library(stargazer) |
``` |
```{r, results='asis'} |
stargazer(attitude) |
``` |
(oddly, the example in the stargazer vignette is wrong. Boo.) |
Running this (Knit HTML) produces an HTML file that looks fine except for the results here. Install Pandoc, and compile the .md file into pdf via LaTeX |
You can do this [online](http://johnmacfarlane.net/pandoc/try/) (but only as far as LaTeX), or [install pandoc](http://johnmacfarlane.net/pandoc/) and do it from your computer. But you'll have to install LaTeX and that's a giant hassle. |
Alternatively, there are some HTML table packages (e.g. R2HTML, xtable) that might be a better way forward. If markdown is your target document format, you could look at the '[markdown](http://cran.r-project.org/web/packages/markdown)' package to produce markdown tables that will work with the same code as above. |
Any advice for how to convert a latex file to R markdown, even imperfectly? My problem is that I want to use some of the material from the OpenIntro project, specifically Appendix A on Probability from Intro Stat with Randomization and Simulation. They provide the latex source files from which the PDF is created. How can I turn that latex source into R markdown?
Here is a copy of the key file. I provide it since it is a bit bothersome to get this directly from OpenIntro.
For reference, below is the top of the latex source. I realize that latex has options with no analog in Rmd, so no conversion will be perfect. I just assume/hope that someone else has already written a converter.
chapter{Probability}
label{probability}
index{probability|(}
Probability forms a foundation for statistics. You might already be familiar with many aspects of probability, however, formalization of the concepts is new for most. This chapter aims to introduce probability on familiar terms using processes most people have seen before.
section{Defining probability}
label{basicsOfProbability}
begin{example}{A ``die', the singular of dice, is a cube with six faces numbered resp{1}, resp{2}, resp{3}, resp{4}, resp{5}, and resp{6}. What is the chance of getting resp{1} when rolling a die?}label{probOf1}
If the die is fair, then the chance of a resp{1} is as good as the chance of any other number. Since there are six outcomes, the chance must be 1-in-6 or, equivalently, 1/6.
end{example}
begin{example}{What is the chance of getting a resp{1} or resp{2} in the next roll?}label{probOf1Or2}
resp{1} and resp{2} constitute two of the six equally likely possible outcomes, so the chance of getting one of these two outcomes must be 2/6 = 1/3.
end{example}
begin{example}{What is the chance of getting either resp{1}, resp{2}, resp{3}, resp{4}, resp{5}, or resp{6} on the next roll?}label{probOf123456}
100%. The outcome must be one of these numbers.
end{example}
begin{example}{What is the chance of not rolling a resp{2}?}label{probNot2}
Since the chance of rolling a resp{2} is 1/6 or 16.bar{6}%, the chance of not rolling a resp{2} must be 100% - 16.bar{6}%=83.bar{3}% or 5/6.
Alternatively, we could have noticed that not rolling a resp{2} is the same as getting a resp{1}, resp{3}, resp{4}, resp{5}, or resp{6}, which makes up five of the six equally likely outcomes and has probability 5/6.
end{example}
Latex R Markdown Example
begin{example}{Consider rolling two dice. If 1/6^{th} of the time the first die is a resp{1} and 1/6^{th} of those times the second die is a resp{1}, what is the chance of getting two resp{1}s?}label{probOf2Ones}
If 16.bar{6}% of the time the first die is a resp{1} and 1/6^{th} of emph{those} times the second die is also a resp{1}, then the chance that both dice are resp{1} is (1/6)times (1/6) or 1/36.
end{example}
textA{newpage}
subsection{Probability}
index{random process|(}
We use probability to build tools to describe and understand apparent randomness. We often frame probability in terms of a term{random process} giving rise to an term{outcome}.
begin{center}
begin{tabular}{lll}
Roll a die &rightarrow & resp{1}, resp{2}, resp{3}, resp{4}, resp{5}, or resp{6}
Flip a coin &rightarrow & resp{H} or resp{T}
end{tabular}
end{center}
Rolling a die or flipping a coin is a seemingly random process and each gives rise to an outcome.
begin{termBox}{tBoxTitle{Probability}
The term{probability} of an outcome is the proportion of times the outcome would occur if we observed the random process an infinite number of times.}
end{termBox}
Probability is defined as a proportion, and it always takes values between 0~and~1 (inclusively). It may also be displayed as a percentage between 0% and 100%.
Probability can be illustrated by rolling a die many times. Let hat{p}_n be the proportion of outcomes that are resp{1} after the first n rolls. As the number of rolls increases, hat{p}_n will converge to the probability of rolling a resp{1}, p = 1/6. Figure~ref{dieProp} shows this convergence for 100,000 die rolls. The tendency of hat{p}_n to stabilize around p is described by the term{Law of Large Numbers}.
Latex R Markdown Cheat Sheet
begin{figure}[bt]
centering
includegraphics[width=0.8textwidth]{appendix-probability/figures/dieProp/dieProp}
caption{The fraction of die rolls that are 1 at each stage in a simulation. The proportion tends to get closer to the probability 1/6 approx 0.167 as the number of rolls increases.}
label{dieProp}
end{figure}