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 726969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:30:47+00:00 2026-05-14T06:30:47+00:00

I have a dataframe with a column of integers that I would like to

  • 0

I have a dataframe with a column of integers that I would like to use as a reference to make a new categorical variable. I want to divide the variable into three groups and set the ranges myself (ie 0-5, 6-10, etc). I tried cut but that divides the variable into groups based on a normal distribution and my data is right skewed. I have also tried to use if/then statements but this outputs a true/false value and I would like to keep my original variable. I am sure that there is a simple way to do this but I cannot seem to figure it out. Any advice on a simple way to do this quickly?

I had something in mind like this:

x   x.range
3   0-5
4   0-5
6   6-10
12  11-15
  • 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-05-14T06:30:48+00:00Added an answer on May 14, 2026 at 6:30 am

    Ian’s answer (cut) is the most common way to do this, as far as i know.

    I prefer to use shingle, from the Lattice Package

    the argument that specifies the binning intervals seems a little more intuitive to me.

    you use shingle like so:

    # mock some data
    data = sample(0:40, 200, replace=T)
    
    a = c(0, 5);b = c(5,9);c = c(9, 19);d = c(19, 33);e = c(33, 41)
    
    my_bins = matrix(rbind(a, b, c, d, e), ncol=2)
    
    # returns: (the binning intervals i've set)
            [,1] [,2]
     [1,]    0    5
     [2,]    5    9
     [3,]    9   19
     [4,]   19   33
     [5,]   33   41
    
    shx = shingle(data, intervals=my_bins)
    
    #'shx' at the interactive prompt will give you a nice frequency table:
    # Intervals:
       min max count
    1   0   5    23
    2   5   9    17
    3   9  19    56
    4  19  33    76
    5  33  41    46
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataframe with one column that I would like to split into
I have a dataframe and would like to add a new column where the
I'd like to melt the dataframe so that in one column I have dates
I have a two column dataframe in R and i want to add a
I have a state column in a dataframe and I want to create two
I have a dataframe called data where I would like to rescale the values
I have a dataframe that looks like this DF: V1 V2 V3 V4 V5
I would like to transform/modify the content of dataframe. Basically I have a dataframe
I'm working in R. I have a dataframe, df that looks like this: >
I have a dataframe like x where the column genes is a factor. I

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.