[R] Sweave scientific real display format (e.g. 5e-12)

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Fri Mar 10 11:37:41 CET 2006


you may try something along these lines:

num2Latex <- function (x, digits = 0) {
    op <- options(scipen = -digits)
    on.exit(options(op))
    x <- as.character(x)
    ind <- grep("e", x)
    x[ind] <- sapply(strsplit(x[ind], "e"), function(s) paste(s[1], 
"e", as.numeric(s[2]), sep = ""))
    x[ind] <- paste(gsub("e", " \\cdot 10^{", x[ind], fixed = TRUE), 
"}", sep = "")
    cat(paste(x, "\n"))
}
#################
z <- c(1.5, 5e-12, 2.33e-03, 8.12e+10, 2)
num2Latex(z)
num2Latex(z, 2)
num2Latex(z, -3)


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "BORGULYA Gábor" <borgulya at gyer2.sote.hu>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, March 10, 2006 10:44 AM
Subject: [R] Sweave scientific real display format (e.g. 5e-12)


Dear All,

I couldn't figure and couldn't google out how to make construct a pair 
of
\Sexpr s or a LaTeX macro that would include
      5\cdot 10^{-12}
into the LaTeX output istead of
      5e-12 .

Any ideas?

Thank you

Gábor

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm




More information about the R-help mailing list