numeric(0) -> NA
Peter Dalgaard BSA
09 Jul 1998 12:37:25 +0200
Bill Simpson <email@example.com> writes:
> I noticed this in current intermediate patch version:
> > runif(0,0,4095)
> > round(runif(0,0,4095))
>  NA
> I don't like it, but maybe it is the way it is supposed to be. I would
> prefer for it to stay numeric(0).
> I notice also
> > ceiling(runif(0,0,4095))
> > floor(runif(0,0,4095))
> which leads me to thing round() is not working right.
You're right, but it's not all that easily fixed. The problem is that
round() unlike the other two isn't a unary operation (it has a digits
argument) and the automatic logic for binary functions is that
length(f(a,b)) = max(length(a),length(b)).
There are several of these anomalies, e.g.:
whereas Splus has
# choose doesn't exist...
I.e. it seems to special-case *some* functions....
We probably should have a special version of math2() which said that
the first argument was more important than the other.
> BTW I think it is a ghastly waste of resources to do
> but I couldn't think of a better way to get ints between 0 and 4095.
> (It's a waste because the random number generator makes unsigned long ints
> to begin with, then they are divided by 2^32 to get a double between 0
> and 1, and now I am undoing that!)
Compared to all the other inefficiencies going on, I don't think this
is worth worrying about (unless nnoise is *very* large). If you really
need this to be efficient, you could make a clone of runif in .C
callable code, and replace the floatingpoint (l / 2.^32) by a shift
operation (l >> 18 or thereabouts).
> I guess there is sample(,replace=true), which seems even worse for
> wasted resources. Maybe not.
Most likely it is...
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (firstname.lastname@example.org) FAX: (+45) 35327907
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: email@example.com