How to generate bin frequency table in R?

try

 as.data.frame(table(cut(x, breaks=seq(0,1, by=0.1)), dnn="Range"))

Regarding @akrun solution, I would post something usefull from the documentation ?cut, in case:

Note

Instead of table(cut(x, br)), hist(x, br, plot = FALSE) is more efficient and less memory hungry.

So, in case of lots of data, I would rather opt for:

br = seq(0,1,by=0.1)

ranges = paste(head(br,-1), br[-1], sep=" - ")
freq   = hist(x, breaks=br, include.lowest=TRUE, plot=FALSE)

data.frame(range = ranges, frequency = freq$counts)

#       range frequency
#1    0 - 0.1         2
#2  0.1 - 0.2         1
#3  0.2 - 0.3         3
#4  0.3 - 0.4         5
#5  0.4 - 0.5         4
#6  0.5 - 0.6         1
#7  0.6 - 0.7         2
#8  0.7 - 0.8         0
#10   0.9 - 1         1

Tags:

R

Bin