Use scientific notation with xtable in R

2020-08-10 08:32发布

问题:

I pass a data.frame to xtable

 dat.table <- xtable(dat[1:20,] ,digits=10)

Instead of displaying digits like that, I would prefer to use scientific notation. How would I do that?

had a look but all I found was R: formatting the digits in xtable which isn't the answer it seems.

回答1:

Try:

dat.table <- xtable(dat[1:20,] ,digits=-10)

"If values of digits are negative, the corresponding values of x are displayed in scientific format with abs(digits) digits." xtable



回答2:

If you are wanting to x10^ notation trying use print and xtable. something like:

print(xtable(dat[1:10,1:7], display=c("s","s", "s","s","g","g","g","g")), math.style.exponents = TRUE)

where s is string and g is used for scientific notation (only when space is saved), themath.style.exponents from print will convert to x10^format.



标签: r