在 RStudio 中,我得到像 1e-2 或 4e-35 这样的科学记数法结果。我正在使用 xtable 将这些数字导出到乳胶,但希望它们看起来像乳胶中的常规格式,即,$1 \times 10^{-2}$或$4 \times 10^{-35}$. 如何在 R 中编码以获得像 xtable 输出这样的常规科学记数法格式?
我有数据:
transaction <- c(1,2,3);
date <- c("2010-01-31","2010-02-28","2010-03-31");
type <- c("debit", "debit", "credit");
amount <- c(-500, -1000.97, 12500.81);
oldbalance <- c(5000, 4500, 17000.81)
evolution <- data.frame(transaction, date, type, amount, oldbalance, row.names=transaction, stringsAsFactors=FALSE);
evolution$date <- as.Date(evolution$date, "%Y-%m-%d");
evolution <- transform(evolution, newbalance = oldbalance + amount);
evolution
Run Code Online (Sandbox Code Playgroud)
如果我想创建一个数字amount等于1位小数的表,这样的命令是否有效?
> tab.for <- formatC(evolution$amount,digits=1,format="f")
> tab.lat <- xtable(tab.for)
Error in UseMethod("xtable") :
no applicable method for 'xtable' applied to an object of class "character"
Run Code Online (Sandbox Code Playgroud)
谢谢.