Histograms group numeric values into intervals. Wider breaks combine more values into each bin.

Program

Play the script to change break width and see which histogram bin receives the most values.

histogram_bins.R
values <- c(2, 4, 4, 5, 7, 8, 9, 10)
break_width <- 
breaks <- seq(0, 12, by = break_width)
histogram <- hist(values, breaks = breaks, plot = FALSE)
counts <- histogram$counts
labels <- paste(head(breaks, -1), tail(breaks, -1), sep = "-")
peak <- labels[which.max(counts)]
cat(peak, "\n", sep = "")
values <- c(2, 4, 4, 5, 7, 8, 9, 10)
break_width <- 
breaks <- seq(0, 12, by = break_width)
histogram <- hist(values, breaks = breaks, plot = FALSE)
counts <- histogram$counts
labels <- paste(head(breaks, -1), tail(breaks, -1), sep = "-")
peak <- labels[which.max(counts)]
cat(peak, "\n", sep = "")
values <- c(2, 4, 4, 5, 7, 8, 9, 10)
break_width <- 
breaks <- seq(0, 12, by = break_width)
histogram <- hist(values, breaks = breaks, plot = FALSE)
counts <- histogram$counts
labels <- paste(head(breaks, -1), tail(breaks, -1), sep = "-")
peak <- labels[which.max(counts)]
cat(peak, "\n", sep = "")
hist `hist(..., plot = FALSE)` computes bins and counts without drawing a chart.
breaks `breaks` defines the interval boundaries used by the histogram.
which.max `which.max(counts)` selects the first bin with the largest count.