# [R] rep() fails at times=0.29*100

arun smartpink111 at yahoo.com
Tue Apr 9 18:58:56 CEST 2013

```Possibly R FAQ 7.31

length(rep(TRUE,signif(0.29*100,2)))
# 29
A.K.

----- Original Message -----
From: Jorge Fernando Saraiva de Menezes <jorgefernandosaraiva at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Tuesday, April 9, 2013 12:11 PM
Subject: [R] rep() fails at times=0.29*100

Dear list,

I have found an unusual behavior and would like to check if it is a
possible bug, and if updating R would fix it. I am not sure if should post
it in this mail list but I don't where is R bug tracker. The only mention I
found that might relate to this is "If times is a computed quantity it is
prudent to add a small fuzz." in rep() help, but not sure if it is related
to this particular problem

Here it goes:

> rep(TRUE,29)
 TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
 TRUE TRUE
> rep(TRUE,0.29*100)
 TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
 TRUE
> length(rep(TRUE,29))
 29
> length(rep(TRUE,0.29*100))
 28

Just to make sure:
> 0.29*100
 29

This behavior seems to be independent of what is being repeated (rep()'s
first argument)
> length(rep(1,0.29*100))
 28

Also it occurs only with the 0.29.
> length(rep(1,0.291*100))
 29
> for(a in seq(0,1,0.01)) {print(sum(rep(TRUE,a*100)))} #also shows correct
values in values from 0 to 1 except for 0.29.

I have confirmed that this behavior happens in more than one machine
(though I only have session info of this one)

> sessionInfo()
R version 2.15.3 (2013-03-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
 LC_COLLATE=Portuguese_Brazil.1252  LC_CTYPE=Portuguese_Brazil.1252
LC_MONETARY=Portuguese_Brazil.1252
 LC_NUMERIC=C                       LC_TIME=Portuguese_Brazil.1252

attached base packages:
 stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
 spatstat_1.31-1 deldir_0.0-21   mgcv_1.7-22

loaded via a namespace (and not attached):
 grid_2.15.3     lattice_0.20-13 Matrix_1.0-11   nlme_3.1-108
tools_2.15.3

[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help