在FlexTable中格式化数字

编程入门 行业动态 更新时间:2024-10-28 11:34:50
本文介绍了在FlexTable中格式化数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用ReporteRs通过以下代码生成flexTable:

I am using ReporteRs to generate a flexTable using the following piece of code:

library( ReporteRs ) baseCellProp <- cellProperties( padding = 2 ) baseParProp <- parProperties(text.align = "center") ft.list <- list(mua= 1, mub = 2, mug = 1e-7) ft.data <- t(data.frame(ft.list)) ft.FlexTable <- FlexTable( data = ft.data, add.rownames = TRUE, header.columns = FALSE, body.cell.props = baseCellProp, body.par.props = baseParProp) ft.FlexTable <- setFlexTableWidths(ft.FlexTable, widths =c(1,2)) ft.FlexTable

我遇到的问题是所有数字都以这样的科学计数法表示出来:

The problem I am having is all the numbers are coming out in scientific notation like this:

mua 1e+00 mub 2e+00 mug 1e-07

有没有办法告诉flexTable如何格式化数字?具体来说,不是对所有行都应用相同的格式,而是对逐行应用有意义的格式?

Is there a way to tell flexTable how to format numbers? Specifically do not apply the same format to all the rows, but apply a format that makes sense on a row-by-row basis?

推荐答案

我使用了 r转置数据帧.问题是将数据帧框架转换为所有元素都必须转换为字符.使用矩阵可以解决该问题:

I solved my problem using a hint from r transposing a data frame. The problem was transposing a data frame frame coerces all the elements to characters. Using matrices solves that problem:

ft.list <- list(mua= 1, mub = 2, mug = 1e-7) ft.data <- as.matrix(ft.list, rownames.force=TRUE )

更多推荐

在FlexTable中格式化数字

本文发布于:2023-05-28 12:26:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/320862.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数字   FlexTable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!