[R] creating categorical frequency tables from continuous data

Louise Mair lm609 at york.ac.uk
Thu Jan 27 15:58:56 CET 2011


Hello,

I am working with a dataset which essentially has only one column - a 
list of distances in metres, accurate to several decimal places. eg

distance
1000
6403.124
1000
1414.214
1414.214
1000

I want to organise this into a frequency table, grouping into categories 
of 0 - 999,  1000 - 1999, 2000-2999 etc. I'd also like the rows where 
there are no data points in that category to contain 0, in order to be 
able to plot a histrogram with a linear x axis, and to statistically 
analyse differences between datasets.

I have tried table()  which doesn't group the data the way I'd like it, 
I've also tried cut() but couldn't make it work. Ideally I'd like the 
output to look something like this...

distance        frequency
0-999            0
1000-1999   3
2000-2999   0
...

Any suggestions that are an improvement on doing it manually please?

Thanks in advance!

Louise



More information about the R-help mailing list