I have a data.frame with a column with values ranging from 0 to 50.000. I want to create create 5 categories for this data in order to plot it in a categorized histogram.
What I want to do is to create a column that tells me which is the category this value belongs in order to plot it. For instance I decided to create the following categories:
[1,3] (3,6] (6,12] (12,30] (30,50000]
Is this possible? There is an easier way to do that? I normally use ggplot2 library for the plots.
Thanks in advance.
See
?cut. Here is an example:This gives:
If you want that in the data frame, try this instead:
Which results in
You can change the levels of the resulting factors if you want to give different labels to them.