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

  • Home
  • SEARCH
  • 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 6609377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:42:39+00:00 2026-05-25T19:42:39+00:00

I have a table called tableOne in R like this: idNum binaryVariable salePrice 2

  • 0

I have a table called tableOne in R like this:

idNum        binaryVariable        salePrice
2               1                    55.56
4               0                    88.33
15              0                     4.45
87              1                    35.77
...            ...                    ...

I’d like to take the values produced from: summary(tableOne$salePrice) to create four quartiles by salePrice. I’d then like to create a column tableOne$quartile with which quartile each rows salePrice is in. It would look like:

idNum        binaryVariable            salePrice      quartile
    2               1                    55.56            3
    4               0                    88.33            4
    15              0                     4.45            1
    87              1                    35.77            2 
    ...            ...                    ...            ...  

Any suggestions?

  • 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-25T19:42:40+00:00Added an answer on May 25, 2026 at 7:42 pm

    This should do it:

    tableOne <- within(tableOne, quartile <- as.integer(cut(salesPrice, quantile(salesPrice, probs=0:4/4), include.lowest=TRUE)))
    

    …Some details:

    The within function is great for calculating new columns. You don’t have to refer to columns as
    tableOne$salesPrice etc.

    tableOne <- within(tableOne, quartile <- <<<some expression>>>)
    

    The quantile function calculates the quantiles (or in your case, quartiles). 0:4/4 evaluates to c(0, 0.25, 0.50, 0.75, 1).

    Finally the cut function splits your data into those quartiles. But you get a factor with weird names, so as.integer turns it into groups 1,2,3,4.

    Try ?within etc to learn more about the functions mentioned here…

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

Sidebar

Related Questions

hi i have table called products with columns product_id prodcut_name prodcut_price( values like 1200,2000,3000,100)
i have table called table1 and it looks like the below record type tran_ref_number
I have table called location with a field area. This field can contain various
I have a table called user_details this table has got morethan 100k user details
I have a table called reports it looks like: user_id | report_post 1 2
I have a table called Shoppings in my SQL db. This one has a
I have table called Data_Details and the data looks like: DateTimeClosed Datesub TimeSub 6/20/2011
I have table called stats . In am inserting yes or no in the
I have a table called OffDays, where weekends and holiday dates are kept. I
I have a Table called Product and I have the Table StorageHistory . Now,

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.