[R] round and trailing zero

Göran Broström gb @end|ng |rom eh@r@@e
Mon Jul 29 16:06:18 CEST 2024


I have a "result":

 > hazards
         (60, 70]    (70, 80]    (80, 90]   (90, 100]
[1,] 0.046612937 0.115643783 0.273613266 0.450127975

Two issues: (i) Too many decimals, and (ii) it seems to be an 1x4 
matrix, I only need the first row. (i):

 > haz <- round(hazards, 3)
 > haz
      (60, 70] (70, 80] (80, 90] (90, 100]
[1,]    0.047    0.116    0.274      0.45

As expected, the fourth element lost a trailing zero. I'll deal with 
that, but first (ii):

 > haz[1, ]
  (60, 70]  (70, 80]  (80, 90] (90, 100]
     0.047     0.116     0.274     0.450

And the trailing zero is mysteriously recovered!

Is there some general rule governing this behaviour?

Thanks, Göran



More information about the R-help mailing list