[R] Strange R behavior for product of two sum of integers

peter dalgaard pdalgd at gmail.com
Thu Oct 20 17:37:14 CEST 2011


On Oct 20, 2011, at 16:50 , David Winsemius wrote:

> That does seem to be an infelicity that ought to be fixed. Using the infix addition operator does that same sort of coercions, so why would one expect the infix multiplication operator to refuse to do it?
> 
> > (sum(1000:1205))*(sum(1000:1204) +1205)
> [1] 51581223225

The addition operator doesn't either:

> (sum(1000:1205))*(sum(1000:1204) +1205L)
[1] NA
Warning message:
In (sum(1000:1205)) * (sum(1000:1204) + 1205L) :
  NAs produced by integer overflow

Beware that 1:1 is integer but 1 is not.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list