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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:59:24+00:00 2026-05-16T01:59:24+00:00

When programming within the R environment I used rep([35,40),1020). This should give me a

  • 0

When programming within the R environment I used rep(“[35,40)”,1020). This should give me a list with 1020 times “[35,40)”. However, the result contains only 1019 of these elements.

The programming was first done within a replicated for two vectors, but even when I split it up it doesn’t work.

What I tried is using differen versions of R (R 2.11.1, R 2.9.0, R 2.10.0, R 2.7.2) but in none of them it works properly.

Has anyone an idea if there is a version of R which doesn’t have this bug? Or how I could solve this problem?

So the code for this:

> agecats
 [1] "(-0.001,5]" "(5,10]"     "(10,15]"    "(15,20]"    "(20,25]"   
 [6] "(25,30]"    "(30,35]"    "(35,40]"    "(40,45]"    "(45,50]"   
[11] "(50,55]"    "(55,60]"    "(60,65]"    "(65,70]"    "(70,75]"   
[16] "(75,80]"  
> weightage<-c(0.9,0.9,2.7,3.1,8.9,10.05,10.05,10.2,10.2,9.3,9.3,8.7,7.9,3.15,3.15,1.5)
> weightage
 [1]  0.90  0.90  2.70  3.10  8.90 10.05 10.05 10.20 10.20  9.30  9.30  8.70
[13]  7.90  3.15  3.15  1.50

> weightage100<-weightage*100
> weightage100
 [1]   90   90  270  310  890 1005 1005 1020 1020  930  930  870  790  315  315
[16]  150
> tosamplefrom<-rep(agecats,weightage100)
> table(tosamplefrom)
tosamplefrom
(-0.001,5]    (10,15]    (15,20]    (20,25]    (25,30]    (30,35]    (35,40] 
        90        270        310        890       1005       1005       1019 
   (40,45]    (45,50]     (5,10]    (50,55]    (55,60]    (60,65]    (65,70] 
      1019        930         90        930        869        790        315 
   (70,75]    (75,80] 
       315        150 

And here I should have the 8 and 9 1020 times and it just gives 1019 times.

Kim

  • 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-16T01:59:24+00:00Added an answer on May 16, 2026 at 1:59 am
    (10.20 * 100) == 1020
    FALSE
    

    This is your problem. 10.2 can’t be represented exactly and everything is going to hell because you’re multiplying a floating point number and assuming it’s an integer. It appears that R must be taking the floor of the number or just using as.integer for the conversion:

    floor(10.2*100)
    1019
    as.integer(10.2*100)
    1019
    

    Rounding will work whether the floating point value is slightly above or slight below. The following change does fix the problem.

    weightage100 <- round (weightage*100)
    

    Read the R Inferno (floating point problems like this are not exclusive to R, for example, I just replicated it in python)

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

Sidebar

Related Questions

My programming environment includes scripts for setting up my autobuild on a clean machine.
Being relatively new to functional programming, I expend lots of energy wondering is this
I am programming in a Hebrew environment and so I want the tabs on
In this case the application which sets the environment variable is executed in/from the
Programming Student here...trying to work on a project but I'm stuck. The project is
Programming in vim I often go search for something, yank it, then go back
Programming languages had several (r)evolutionary steps in their history. Some people argue that model-driven
Programming PHP in Eclipse PDT is predominately a joy: code completion, templates, method jumping,
Programming is learned by writing programs. But code reading is said to be another
Some programming languages such as Java and C# include encryption packages in their standard

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.