R: When using rep (.., ..) to replicate 1020 character variables, does the result contain only 1019 replicates?

When programming in 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 in replicated for two vectors, but even when I laid it out, it does not work.

I tried to use different versions of R (R 2.11.1, R 2.9.0, R 2.10.0, R 2.7.2), but it does not work properly in any of them.

Does anyone have an idea if there is a version of R that does not have this error? Or how can I 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 have to have 8 and 9 1020 times, and it just gives 1019 times.

Kim

+3
1
(10.20 * 100) == 1020
FALSE

. 10.2 , , . , R as.integer :

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

, . .

weightage100 <- round (weightage*100)

R Inferno ( , , R, , python)

+11

Source: https://habr.com/ru/post/1756897/


All Articles