在dplyr中使用group_by时格式化R中的数字

时间:2018-02-14 10:09:18

标签: r dplyr

我目前有以下R代码,它根据BLANLIMAMT列中的值将数据分组为“波段”。这非常有效。

library(dplyr)


#Import the data
MyData <- read.csv("LibFile.csv", stringsAsFactors = FALSE)

#Profile the Data
bTable<- MyData %>% 
  group_by(gr=cut(BLANLIMAMT, breaks= seq(0, 50000000, by = 500000)) )%>% 
  summarise(n= n()) %>%
  arrange(as.numeric(gr))

我的问题是格式化输出。列gr(在bTable中)中的值当前看起来像(0,5e + 05)。我希望它们看起来像0到500,000等。这是表格的截图:

Here is a screenshot of the table

关于如何实现这一目标的任何想法?

2 个答案:

答案 0 :(得分:1)

在剪切中使用dig.lab=8。例如

bTable<- MyData %>% 
  group_by(gr=cut(BLANLIMAMT, breaks= seq(0, 50000000, by = 500000), dig.lab=8) )%>% 
  summarise(n= n()) %>%
  arrange(as.numeric(gr))

它在转换为科学记数法之前给出了位数。

答案 1 :(得分:0)

使用DEBUG: setDebug: JavaMail version 1.5.5

您可以根据自己的喜好玩精确的数字:)。

'scipen':整数。决定以固定或指数表示法打印数值时应用的惩罚。正值偏向固定和负向科学记数:固定符号将是首选,除非它比'scipen'数字更宽。

来源:https://stat.ethz.ch/R-manual/R-devel/library/base/html/options.html