utils :: View显示的数字是否可以格式化?

时间:2015-02-09 17:06:27

标签: r formatting

使用R&#39 {s} View()功能时,有没有办法控制数字格式?我想将数值输出限制为%4.2f(使用sprint时)。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:2)

看看这个:

X <- data.frame(a = c(921.131331,22.23523523, 3.5325), b = c(11.1435, 7.35, 8))

num.of.decimals <- 2
View(format(X, digits = num.of.decimals + 1))

或者:

X <- data.frame(a = c(921.131331,22.23523523, 3.5325), b = c(11.1435, 7.35, 8))

num.of.decimals <- 2

options(digits = num.of.decimals + 1)

View(X)