Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7908907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:08:53+00:00 2026-06-03T12:08:53+00:00

I have a data.frame with a column with values ranging from 0 to 50.000.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:08:54+00:00Added an answer on June 3, 2026 at 12:08 pm

    See ?cut. Here is an example:

    set.seed(42)
    dat <- data.frame(Values = sample.int(50000, size = 100))
    ## create factor indicating which categoriesy data are in    
    grps <- with(dat, cut(Values, breaks = c(1,3,6,12,30,50000)))
    

    This gives:

    > head(grps)
    [1] (30,5e+04] (30,5e+04] (30,5e+04] (30,5e+04] (30,5e+04] (30,5e+04]
    Levels: (1,3] (3,6] (6,12] (12,30] (30,5e+04]
    > table(grps)
    grps
         (1,3]      (3,6]     (6,12]    (12,30] (30,5e+04] 
             0          0          1          0         99
    

    If you want that in the data frame, try this instead:

    dat2 <- within(dat, Groups <- cut(Values, breaks = c(1,3,6,12,30,50000)))
    

    Which results in

    > head(dat2)
      Values     Groups
    1  45741 (30,5e+04]
    2  46853 (30,5e+04]
    3  14307 (30,5e+04]
    4  41520 (30,5e+04]
    5  32085 (30,5e+04]
    6  25953 (30,5e+04]
    

    You can change the levels of the resulting factors if you want to give different labels to them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame with two columns. First column contains categories such as
I have a 3 column data frame which looks a little like this: id
Let's say I have a data frame with numerical values like this AA01.AVG_Beta AA02.AVG_Beta
Suppose I have a data frame with a column for values and another column
I am trying create a data.frame from which to create a graph. I have
I have a data frame that's ~ 50,000 X 200. The column names are
Running on R 2.13, I want to have a data.frame of several column, the
I have a data frame where some of the columns contain NA values. How
I have a data frame where one particular column has a set of specific
I have a data frame with an id column and some (potentially many) columns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.