I have a question about inline R Markdown code:
I have a finished LaTeX table that looks like this:
\begin{table}[!h]
\centering
\begin{tabular}{ |c|c|c|c|}
\hline
$\textbf{Vorname}$ & $\textbf{Nachname}$ & $\textbf{Email}$ & $\textbf{Stimmen}$ \\
\midrule[1pt]
\specialrule{2pt}{-2pt}{-2pt}
\specialrule{2pt}{0pt}{0.5pt}
`r Table[[2]][[1,1]]` & `r Table[[2]][[1,2]]` & `r Table[[2]][[1,3]]` & `r Table[[2]][[1,4]]`\\ \hline
`r Table[[2]][[2,1]]` & `r Table[[2]][[2,2]]` & `r Table[[2]][[2,3]]` & `r Table[[2]][[2,4]]`\\ \hline
\end{tabular}
\end{table}
Here, I inserted some inline code (e.g. Table[[2]][[1,1]]
) for the entries of the cell. Using the notation r [R code]
. Now I would like to make this table dynamic: The amount of rows if supposed to be be given by a variable n
.
So I want something of this kind:
\begin{table}
[LaTex code]
\specialrule{2pt}{0pt}{0.5pt}
j =0
for (j in 1:n){
`r Table[[2]][[j,1]]` & `r Table[[2]][[j,2]]` & `r Table[[j]][[1,3]]` & `r Table[[2]][[j,4]]` \\ \hline }
\end{tabular}
How can I achieve that?
Table
object and a whole rmarkdown file to test it, is hard to guess what you are trying, but anyway my advice is not make a LaTeX table with R chunks code in every cell, but construct first the table as a R dataframe (ifTable
is not already this) and then export the whole dataframe to LaTeX usingxtable
orkable
. This last part could be as simple aslibrary(xtable); xtable(yourdataframe)
.