R: When using the rep(..,..) to replicate 1020 a character variables, the result contains just 1019 replicates? -


When I programming within the R environment, I used the representative ("[35,40]", 1020) I am It should give me a list with 1020 times "[35,40]" However, only 1019 elements exist in the result.

Programming was repeated for the first two vectors, but even then when I split it does not work.

What I have tried is using different versions of R (R 2.11.1, R 2. 9.0, R 2.10.0, R 2.7.2), but none of these Does not work from

Is there any idea if there is a version of R, which is not in this bug? Or how can I solve this problem?

So the code for this:

  & gt; Agecats [1] "(-0.001.5)" "(510)" "(10.15)" "(15,20)" "(20,25)" [6] "(25,30)" "(3035)" "(35,40)" "(40,45)" "(45,50)" [11] "(50,55)" (5560) "" (606) "" (65,70) "" (70,75) "[16]" (7580) "weight lifting & lt; -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)> Weightlifting [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 & gt; Weightlifting 100 & lt; -weightage * 100> Weightage100 [1] 90 90 270 310 890 1005 1005 1020 1020 930 9 30 870 790 315 315 [16] 150 & gt; tosamplefrom & lt; -rep (agecats, weightage100) & gt; Table (tosamplefrom) Tosamplefrom (-0.001.5) (10, 15] (15,20) (20,25) (2530) (3035) (3540) 90 270 310 890 1005 1005 101 9 (40,45) (45,50) (5, 10) (50,55) (5560) (6065) (6570) 101 9 30 90 9 30 869 790 315 (70, 75) (7580) 315 150  

And here I have 8 and 9 1020 times And it only gives 101 9 times.

Kim

  (10.20 * 100) == 1020 incorrect  

This is your problem. 10.2 can not be represented at all and everything is going to hell because you are multiplying a floating point number and assuming that it is an integer, it seems that the R number floors should be taken or simply the conversion Using as.integer for:

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

rounding It will work if the floating point value is slightly above or slightly lower. The following change fixes the problem.

  Lifetime 100 & lt; - Read (Weightage * 100)  

(Such floating point problems are not unique to R, for example, I have repeated it in Python)


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -