Avoid Scientific Notation in Cut Function in R

cut function in R- labeling without scientific notations for use in ggplot2

Use argument dig.lab in cut function:

a<-c(1,10,100,1000,100000,1000000)
b<-cut(a,
breaks=data.frame(
classIntervals(
a,n=3,method="quantile")[2])[,1],
include.lowest=T,dig.lab=10) ##Number of digits used
b
[1] [1,70] [1,70] (70,34000] (70,34000]
[5] (34000,1000000] (34000,1000000]
Levels: [1,70] (70,34000] (34000,1000000]

Avoid Scientific notation in cut function in R

As suggested by Pascal,

Try with adding the argument dig.lab = 5 to cut function.

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

The point where you have to specify what levels you are interested in, is a cut function. So easiest way is:

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]

See ?cut for more information.

Show cut categories in R without e formatting

Try this:

#Code
num_seq <- 1:2000
break_m <- seq(0, 2000, by=30)
num_broken <- cut(num_seq, breaks = break_m,dig.lab = 10)
unique(num_broken)

Outout:

 [1] (0,30]      (30,60]     (60,90]     (90,120]    (120,150]   (150,180]   (180,210]  
[8] (210,240] (240,270] (270,300] (300,330] (330,360] (360,390] (390,420]
[15] (420,450] (450,480] (480,510] (510,540] (540,570] (570,600] (600,630]
[22] (630,660] (660,690] (690,720] (720,750] (750,780] (780,810] (810,840]
[29] (840,870] (870,900] (900,930] (930,960] (960,990] (990,1020] (1020,1050]
[36] (1050,1080] (1080,1110] (1110,1140] (1140,1170] (1170,1200] (1200,1230] (1230,1260]
[43] (1260,1290] (1290,1320] (1320,1350] (1350,1380] (1380,1410] (1410,1440] (1440,1470]
[50] (1470,1500] (1500,1530] (1530,1560] (1560,1590] (1590,1620] (1620,1650] (1650,1680]
[57] (1680,1710] (1710,1740] (1740,1770] (1770,1800] (1800,1830] (1830,1860] (1860,1890]
[64] (1890,1920] (1920,1950] (1950,1980] <NA>
66 Levels: (0,30] (30,60] (60,90] (90,120] (120,150] (150,180] (180,210] ... (1950,1980]

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

The point where you have to specify what levels you are interested in, is a cut function. So easiest way is:

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]

See ?cut for more information.

How can I avoid to show values in scientific notation in R?

You could use mapply and format to create the labels:

TablaFrecs = function(x,k,A,p){
options(scipen=999)
L = min(x)-p/2+A*(0:k)
labels = mapply(function(x,y){paste0("[",format(x),",",format(y),")")},L[-length(L)],L[-1])
x_cut = cut(x,
breaks = L ,
labels = labels,
right=FALSE)
intervals = levels(x_cut)
mc = (L[1]+L[2])/2+A*(0:(k-1))
Fr.abs = as.vector(table(x_cut))
Fr.rel = round(Fr.abs/length(x),4)
Fr.cum.abs = cumsum(Fr.abs)
Fr.cum.rel = cumsum(Fr.rel)
tabla = data.frame(intervals, mc, Fr.abs, Fr.cum.abs, Fr.rel, Fr.cum.rel)
tabla
}

TablaFrecs(1e6, k= 27, A = 3646296, p= 0.1)

intervals mc Fr.abs Fr.cum.abs Fr.rel Fr.cum.rel
1 [999999.9,4646296) 2823148 1 1 1 1
2 [4646296,8292592) 6469444 0 1 0 1
3 [8292592,11938888) 10115740 0 1 0 1
...

Remove Scientific Notation from R plot

The issue is with cut. Use the dig.lab to adjust the digits

CatLotData2$LotCat <-cut(CatLotData2$'LOT SIZE',
c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000,12500,
15000,17500,Inf), dig.lab = 10)


Related Topics



Leave a reply



Submit