Sweave, how can I write R code inside a latex table environment?

Now I'm working on Sweave when I want to use R code to describe a single variable in a latex table.

Turns out Sweave can't read these R codes, the output is not a variable, instead the output is the text form of all the code I'm writing

+3
source share
1 answer

You may need it \Sexpr{R expression}; for example this piece of sweave

<<echo=FALSE>>=
z <- exp(pi)
@

\begin{tabular}{cc}
  a & \Sexpr{z} \\
  b & \Sexpr{round(z,3)}  \\
\end{tabular}

becomes this when Sweaved (Swoven?)

\begin{tabular}{cc}
  a & 23.1406926327793 \\
  b & 23.141  \\
\end{tabular}
+5
source

All Articles