[R] some strange result

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Sat Dec 7 08:50:03 CET 2002


On Sat, 7 Dec 2002, Ahmad Abu Hammour wrote:

> Hi,
> I use R 1.6.1 on my machine. While I working I got some strange result. Here
> is a piece of a longer code:
>
> minb=0.7; stpb=0.1
> minw=0.7; maxw=1.0; stpw=0.1
> nj=((1-minb)/stpb)+1
> ni=((maxw-minw)/stpw)+1
> solm=array(0,c(ni,5,nj))
>
> Everything is OK but if you set minb, minw or both = 0.8 or 0.9
>
> you will get the following error message:
>
> "Error in array(0, c(ni, 5, nj)) : dim<- length of dims do not match the
> length of object"

Works on my machine, but not the dim arguments are supposed to be
integers and your calculations are subject to rounding error.

> One more thing. Try to do the following to get another strange result.
> as.integer((1-0.8)/0.1) which gives you 1 instead of 2.
> as.integer((1-0.9)/0.1) which gives you 0 instead of 1.
> as.integer((1-0.7)/0.1) which gives you 3 which is correct.
>
> This could be a bug or just meant to be like that. I appreciate your help.

?round may help you. as.integer is to do with storage mode, not rounding.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list