BORGULYA Gábor
2006-Mar-10 09:44 UTC
[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
Dimitris Rizopoulos
2006-Mar-10 10:37 UTC
[R] Sweave scientific real display format (e.g. 5e-12)
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
BORGULYA G?bor <borgulya <at> gyer2.sote.hu> writes:> 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 .a =1.3452e-12 asp = strsplit(sprintf("%8.3g",a),"[.e]")[[1]] sprintf("%s\\cdot %s 10^{%s}",asp[1],asp[2],asp[3]) Not really elegant.... Dieter
Ken Knoblauch
2006-Mar-10 12:28 UTC
[R] Sweave scientific real display format (e.g. 5e-12)
Oops,
the third line should have been:
xss<-unlist(strsplit(xc,""))
to get that output but I'm missing something about escaping the backslash,
since
it's missing and when I double it, it doubles. I think that there has
been some
discussion about this on the list, if you look it up.
***********************************
How about some variation on the following:
x <- 5e-12
xc <- as.character(x)
xss<-strsplit(xc, "")
paste("$",xss[1],"\cdot ^{",xss[3],xss[4],
xss[5],"}$", sep = "")
[1] "$5cdot ^{-12}$"
untried, of course, but maybe you could squeeze something out of it.
*********************************
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
--
Ken Knoblauch
Inserm U371
Cerveau et Vision
Dept. of Cognitive Neuroscience
18 avenue du Doyen L?pine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.lyon.inserm.fr/371/