Create a uniform distribution in R and it's histogram is weird

20 Views Asked by At

enter image description here

c1<- seq(1,10,0.1)
hist(c1, breaks = 7, right = FALSE, ylim = c(1,10))

why is there always a part that is higher at the edge?

1

There are 1 best solutions below

2
cherrywoods On BEST ANSWER

It's because there are 11 values in c1 that are between 9.0 and 10.0 (both inclusive). For each other bin, for example, [1, 2) there are only 10 values, as the upper edge belongs to the next bin. But for the last bin, the upper edge (10.0) is included.

If you only run your sequence until 9.9, you get the desired histogram

c1 <- seq(1, 9.9, 0.1)
hist(c1, breaks = 7, right = FALSE, ylim = c(1,10))