-4

I have a data frame in R that has a personal ID, an income and some other variables. I would like to add a new column to this data that categorises people in to which income group they fit in to (0-24,999, 25,000-49,999, 50,000-74,999, 75000-99,000, etc).

I then want to be able to make frequency tables of this data compared with some of the other variables (eg: weekly hours worked, age).

I should be fine to figure out the latter of these problems, but I am having trouble figuring out how to categorise my data. Any help would be greatly appreciated.

Thank you.

lmo
  • 37,904
  • 9
  • 56
  • 69
Fuz
  • 11
  • Thank you akrun. How do I name these categories? (eg: low, medium, high?) – Fuz Mar 31 '16 at 07:00
  • Thank you I now know how to name the categories. – Fuz Mar 31 '16 at 07:21
  • When I try and merge this with my original data set, it duplicated the rows a couple of times, so I have three times as many rows. Any idea what may have caused this? – Fuz Mar 31 '16 at 07:22

1 Answers1

2

We can use cut or findInterval to group the "Variable"

gr <- cut(df1$Variable, breaks = c(0, 24999, 49999,74999,99999, Inf))

Then, use table to get the frequency count

table(gr, df1$age)
akrun
  • 874,273
  • 37
  • 540
  • 662