如何摆脱 cut() 产生的因子的科学记数法

How to get rid of scientific notation for factor produced by cut()

如何去除 factor 变量的默认科学记数法?当我在当前情况下有 3 个或更多数字时,它被 R 使用。

我查看了其他答案 (scipen and other, format),但它们似乎不适用于 factor 变量。

然后我在图例中使用这个因子变量,我需要整数或定点值。

options(scipen=999)
plot(0,0, type="l", lty=1, lwd=4);

var1 <- c(3334,341,36,341,456)
cut1 <- cut(var1, breaks=2)
cut1<-levels(cut1)
cut1<-gsub(","," - ",cut1)
cut1<-gsub("\(","[",cut1)
#cut1 <- as.character(cut1);
#formatC(cut1, digits="10", format="f")
cut1

[1] " [32.7 - 1.68e+03]" "[1.68e+03 - 3.34e+03]

我想要这样的东西:

[1] " [32.7 - 1680]" "[1680 - 3340]"

您必须指定您感兴趣的级别的地方是一个 cut 函数。最简单的方法是:

cut1 <- cut(var1, breaks=2, dig.lab = 5)
[1] (1685,3337.3] (32.702,1685] (32.702,1685] (32.702,1685] (32.702,1685]
Levels: (32.702,1685] (1685,3337.3]

有关详细信息,请参阅 ?cut。