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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:55:41+00:00 2026-06-07T04:55:41+00:00

I’m trying to use the R function quantcut() to recode a numeric variable as

  • 0

I’m trying to use the R function quantcut() to recode a numeric variable as a factor with levels corresponding to quantiles. For example:

> X
[1]  6  4  9  6  1  2  5  3  5  7 10  7  2  7  7  5  6  6  3  4  6  4  2  7  6  7
[27]  4  3  5  3  7  6  8 12  4  4  0  1  7  6  7  4  7  1  1  1  2  3  3  1  1  6
[53]  5  3  1  1  1  3  3  3  1  1  3  1  1  1  3  3  0  1  3  1  8  5  3  0  0  2
[79]  1  3  8  0  1  4  1  1  1  1  1  1  3  2  1  4  1  5  5 12  7  2  6  6  2  6
[105]  0  1  4  1  4  0  7  3  2  1  1  8  5  5  3  0  5  6  2  4  2  2  2  6  4  2
[131]  2  2  2  6  8  5  1  2  8  3  2  7  4  6  6  6  7  5  1  5  5  6  1  4  4  5
[157]  6  2  4  7  2  4 10  6  3  5  2  2  6  6  2  4  5  7  4  5 11  6  6  8  2  4
[183]  4  6 12 16  9  7 14 13 11  5  5  2  2  7  7  6  4  3  4  3  5  4  5  7  9  4
[209]  3 12  4  4  4  8  7  6  1  3  6  7  5  5  6  9  6  4  7  8  5  6  3  6  4  7
[235]  3  3  4  7  5  7  5  9  5  8  3  4  3  2  5  2  4  3  8  4  2  2  1  5  3  5
[261]  8  5  6  4  5  1  1  2  6  2  7  2  4  4  3  3  4 10  5  6 10  2  5  5  0  1
[287]  6  2  5  4  6  6  9  5  5  6  3  8  1  5  1  8  5  2  5  2  4  2  4  4

bins=10
labels = 1:bins
library(gtools)
x2 = quantcut(X, q = seq(0, 1, by=1/bins), labels=labels)

I get the error: “Error in cut.default(x[!flag], breaks = newquant, include.lowest = TRUE, :
‘breaks’ are not unique”. I thought this was because there are ties in the quantiles, but the documentation for quantcut specifically shows an example of how the function can handle ties by using fewer intervals. The error occurs regardless of whether I specify the labels argument.

Any advice would be greatly appreciated.

EDIT: Here is code to enter the variable X:

X = c(6L, 4L, 9L, 6L, 1L, 2L, 5L, 3L, 5L, 7L, 10L, 7L, 2L, 7L, 7L, 
5L, 6L, 6L, 3L, 4L, 6L, 4L, 2L, 7L, 6L, 7L, 4L, 3L, 5L, 3L, 7L, 
6L, 8L, 12L, 4L, 4L, 0L, 1L, 7L, 6L, 7L, 4L, 7L, 1L, 1L, 1L, 
2L, 3L, 3L, 1L, 1L, 6L, 5L, 3L, 1L, 1L, 1L, 3L, 3L, 3L, 1L, 1L, 
3L, 1L, 1L, 1L, 3L, 3L, 0L, 1L, 3L, 1L, 8L, 5L, 3L, 0L, 0L, 2L, 
1L, 3L, 8L, 0L, 1L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L, 1L, 4L, 
1L, 5L, 5L, 12L, 7L, 2L, 6L, 6L, 2L, 6L, 0L, 1L, 4L, 1L, 4L, 
0L, 7L, 3L, 2L, 1L, 1L, 8L, 5L, 5L, 3L, 0L, 5L, 6L, 2L, 4L, 2L, 
2L, 2L, 6L, 4L, 2L, 2L, 2L, 2L, 6L, 8L, 5L, 1L, 2L, 8L, 3L, 2L, 
7L, 4L, 6L, 6L, 6L, 7L, 5L, 1L, 5L, 5L, 6L, 1L, 4L, 4L, 5L, 6L, 
2L, 4L, 7L, 2L, 4L, 10L, 6L, 3L, 5L, 2L, 2L, 6L, 6L, 2L, 4L, 
5L, 7L, 4L, 5L, 11L, 6L, 6L, 8L, 2L, 4L, 4L, 6L, 12L, 16L, 9L, 
7L, 14L, 13L, 11L, 5L, 5L, 2L, 2L, 7L, 7L, 6L, 4L, 3L, 4L, 3L, 
5L, 4L, 5L, 7L, 9L, 4L, 3L, 12L, 4L, 4L, 4L, 8L, 7L, 6L, 1L, 
3L, 6L, 7L, 5L, 5L, 6L, 9L, 6L, 4L, 7L, 8L, 5L, 6L, 3L, 6L, 4L, 
7L, 3L, 3L, 4L, 7L, 5L, 7L, 5L, 9L, 5L, 8L, 3L, 4L, 3L, 2L, 5L, 
2L, 4L, 3L, 8L, 4L, 2L, 2L, 1L, 5L, 3L, 5L, 8L, 5L, 6L, 4L, 5L, 
1L, 1L, 2L, 6L, 2L, 7L, 2L, 4L, 4L, 3L, 3L, 4L, 10L, 5L, 6L, 
10L, 2L, 5L, 5L, 0L, 1L, 6L, 2L, 5L, 4L, 6L, 6L, 9L, 5L, 5L, 
6L, 3L, 8L, 1L, 5L, 1L, 8L, 5L, 2L, 5L, 2L, 4L, 2L, 4L, 4L)
  • 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-07T04:55:44+00:00Added an answer on June 7, 2026 at 4:55 am

    Okay, the issue can be traced to here, where as you say, the 70% and 80% quantiles are the same. quantile is used internally by quantcut

    quantile(X,probs=seq(0,1,0.1))
      0%  10%  20%  30%  40%  50%  60%  70%  80%  90% 100% 
     0.0  1.0  2.0  3.0  3.6  4.0  5.0  6.0  6.0  8.0 16.0 
    

    I can’t see how to address this issue using quantcut itself, but you could always just use cut and quantile and unique in combination to sort it out. From what I can tell, this is what quantcut does internally when there are ties anyway.

    result <- cut(X,unique(quantile(X,probs=seq(0,1,0.1))),include.lowest=TRUE)
    
    > result[2:10]
     [1] (3.6,4] (8,16]  (5,6]   [0,1]   (1,2]   (4,5]   (2,3]   (4,5]   (6,8]  
    #Levels: [0,1] (1,2] (2,3] (3,3.6] (3.6,4] (4,5] (5,6] (6,8] (8,16]
    > X[2:10]
     [1]      4      9      6       1       2       5       3       5       7
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.