I'm using knitr/R-sweave to produce a pdf-document wit LaTeX-code. I want to make a table with some numbers produced by some R calculations in the R-code-chuck above this table. When I usually want to refer to an R object in the LaTeX/knitr-outout I use \Sexpr{}, but it doesn't seem to work within tables.
Here's what I got:
\documentclass{article}
\begin{document}
<<Chunk1>>=
a= "1%"
b= "2%"
c= "3%"
d= "4%"
e= 1
f= 2
g= 3
h= 4
#
\begin{table}[]
\centering
\caption{Simple stratified data splits}
\label{my-label}
\begin{tabular}{lll}
\textbf{Dataset} & \textbf{Observations} & \textbf{Event rate}\\ \hline
Full data & \Sexpr{e} & \Sexpr{a} \\
Training set & \Sexpr{f} & \Sexpr{b} \\
Test set & \Sexpr{g} & \Sexpr{c} \\
Evaluation set & \Sexpr{h} & \Sexpr{d}
\end{tabular}
\end{table}
\end{document}
This gives "Running pdflatex.exe on test.tex...failed"
I get the following from the log
LaTeX Warning: No positions in optional float specifier.
Default added (so using `tbp') on input line 71.
LaTeX Font Info: External font cmex10' loaded for size (Font)
<7> on input line 75. LaTeX Font Info: External fontcmex10'
loaded for size (Font) <5> on input line 75.
[1{C:/Users/Frederik
Hermann/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}
] (test.aux) ) Here is how much of TeX's memory you used: 1244
strings out of 493634 16308 string characters out of 3143709 72572
words of memory out of 3000000 4665 multiletter control sequences out
of 15000+200000 4116 words of font info for 16 fonts, out of 3000000
for 9000 1025 hyphenation exceptions out of 8191
27i,8n,19p,284b,237s stack positions out of
5000i,500n,10000p,200000b,50000s Output written on test.pdf (1 page, 39879 bytes). PDF statistics: 18 PDF objects out of
1000 (max. 8388607) 0 named destinations out of 1000 (max. 500000) 1
words of extra memory for PDF output out of 10000 (max. 10000000)
I'm quite the rookie. Any ideas?
You are inserting things like "1%" or "2%" into the table. The percent symbol is a comment marker in LaTeX, so the rest of the line will be dropped.
You can fix this by using "1\%", "2\%", etc. (so that the percents are escaped). You need the double backslash in R code so that a single backslash makes it through to LaTeX.
Related
I'm trying to replicate on LaTeX the decimal to binary conversion scheme, which should look like this:
64 | 0
32 | 0
16 | 0
And so on, considering the vertical lines have to be connected, so no vertical space between them. Is there a way to do that? That's what I've got so far:
${56\newline28\newline14\newline7\newline3\newline1\newline0\newline}\vert\right{0\newline0\newline0\newline0\newline0\newline1\newline}$
You could use a tabular:
\documentclass{article}
\begin{document}
\begin{tabular}{c|c}
64 & 0\\
32 & 0\\
16 & 0\\
\end{tabular}
\end{document}
A naive approach.
\begin{center}
\begin{tabular}{c|c|c|c}
Division by 2& Quotient & Remainder & Bit $\#$\\
\hline
11/2 & 5&1&0\\
5/2 &2& 1&1\\
2/2 &1& 0&2\\
1/2&0&1&3
\end{tabular}
\end{center}
For a systematic way see https://tex.stackexchange.com/questions/96399/how-can-i-illustrate-decimal-to-binary-conversion and the answers therein.
I have a scenario where I am writing a report in R Markdown and I want text to appear based on the values of 3 different variables. In the example below, I want the text to appear if a is greater than b and c. I have found out that you use eval but Ive only managed to use this with 2 variables as shown in the code below. How do I amend the eval part below to include a, b and c?
a<-6
b<-3
c<-2
```{r conditional_block, echo=FALSE, results='asis', eval=a>b}
cat("6 is greater than 3 and is greater than 2")
```
You can use any kind of conditional logic within the chunk option. If you have more than one condition which needs to be met, you can use the & symbol between them which will require both to be TRUE. Here is a basic example:
a<-6
b<-3
c<-2
a>b & a>c
TRUE
# Make a less than c but bigger than b
a <- 2.5
a>b & a>c
FALSE
If you want to find out more about the use of operators in R, I recommend this page: https://www.statmethods.net/management/operators.html
I'm trying to add vertical lines to LaTeX arrays in my RMarkdown document. The preview in RStudio, the conversion to html and pdf work like a charm. There seems to be a problem when I try to convert this document to word:
---
title: "Array"
output: word_document
---
$$
\begin{array}{cc}
1 & 2 \\
3 & 4 \\
\end{array}
$$
$$
\begin{array}{c|c}
1 & 2 \\
3 & 4 \\
\end{array}
$$
The first array prints correctly but the second (where I added the vertical line) doesn't print at all. In the word document created, only the LaTeX code appears. When I compile, here is the error message I receives:
[WARNING] Could not convert TeX math '
\begin{array}{c|c}
1 & 2 \\
3 & 4 \\
\end{array}
', rendering as TeX:
^
unexpected "|"
expecting letter, white space or "}"
I'm currently using Word 2016.
Thanks
In my case, the data consisted of 8 variables and 500 observations. When I used the leaps() code, instead of showing the $2^8 - 1$ submodels, the output showed only 10 models corresponding to those n, where $n \choose 2$ > 10. How can I get the entire output?
I have a large text file and I want to shuffle the file by chunks of 100 lines. So the order within each chunk of 100 lines is preserved. Is there anyway to accomplish this with only Unix command line tools?
Yes. First split the input file into 100-line chunks named "foo...". Then ask shuf to permute their names. Then cat the results together.
split -l 100 INPUTFILE foo
cat $(/bin/ls foo* | shuf)
You can test this out briefly by creating an input file of the numbers 1 to 100 like so:
seq 1 100 > inputfile.txt
and then using chunks of, say, 5 lines.