[R] Extracting bins and frequencies from frequency table

Ralf B ralf.bierig at gmail.com
Wed Sep 22 20:44:47 CEST 2010


Dear R users,

I would like to great a frequency table from raw data and then access
the classes/bins and
their respective frequencies separately. Here the code to create the
frequency tables:


x1 <- c(1,5,1,1,2,2,3,4,5,3,2,3,6,4,3,8)
t1 <- table(x1)
print(t1[1])

Its easy to plot this, but how do I actually access the frequencies
alone and the bins alone?
Basically I am looking to get:

bins <- c(1, 2, 3, 4, 5, 6, 8)
freq <- c(3, 3, 4, 2, 2, 1, 1)

When running

print(t1[1])

I only get one pair. It seems to be organized that way. Is there a
better way? Perhaps 'table' is not the right approach?

Thanks a lot,
Ralf



More information about the R-help mailing list