I am just starting to write some documents with Sweave/R and I like the \sexpr{} command that lets one tow write numbers directly within text.
If I have a number like mus=0.0002433121, well I can say round it to a number of decimal places e.g.
\Sexpr{round(mus,7)}
How to write it in the scientific notation i.e. as LaTeX would be outputting
2.43 \times 10^{-4}
and can we control the number of significant digits to be outputted like 3 in this example?
I note that a number like sigma = 2000000 is written automatically to 2e + 06 if I specify
\Sexpr{round(sigma,2)}.
I would prefer that it would be written as
2 \times 10^6
same as we would get in LaTeX notation and perhaps giving us the possibility to control the number of significant digits as well.
How to achieve this?
I think this function should work:
Some tests:
If you want the result in math mode you could enter
$signs in thepaste()call.Edit:
Here is a Sweave example: