julia.jacobson at arcor.de
2010-Aug-07  20:02 UTC
[R] Sweave for inclusion of p value in a sentence of a LaTeX document
Dear R Users,
I would like to include the p value in the results returned by the t.test
function in a sentence of a LaTeX document. For this purpose, I use the
following code (file.Rnw):
\documentclass{article}
\begin{document}
The p value for my data was 
<<echo=FALSE>>x<-cbind(1,2,3)
y<-cbind(3,4,5)
t.test(x,y)
@
which is not significant.
\end{document}
I use "R CMD Sweave file.Rnw" and "pdflatex file.tex" to
create a PDF document of it.
However, the all details of the t-test are included in my document and form a
new paragraph in another format than the rest of the original sentence.
The sentence should look like this: "The p value for my data was 0.2879
which was not significant."
Thanks in advance.
Julia
Wassertemperaturen in Deutschland
Sommer, Sonne, Strand - wer braucht Abk?hlung? Die aktuellen Wassertemperaturen
und Windgeschwindigkeiten f?r Deutschlands Badeseen gibt?s auf arcor.de.
Matthieu Dubois
2010-Aug-08  06:16 UTC
[R] Sweave for inclusion of p value in a sentence of a LaTeX document
Dear Julia, 
my way to do that is to attribute the t.test to an object, 
and then refer to its p.value with the function 
\Sexpr
e.g. 
\documentclass{article}
\usepackage{Sweave}
\begin{document}
	
<<echo=FALSE>>	x<-cbind(1,2,3)
	y<-cbind(3,4,5)
	t <- t.test(x,y)
@
	
The p value for my data was \Sexpr{ round(t$p.value, 3) } 
which is not significant.
\end{document}
Best, 
Matthieu
Matthieu Dubois
Post-doctoral researcher
Department of Psychology and Neural Science, NYU