[R] Large integers in R

Bert Gunter gunter.berton at gene.com
Fri Jan 29 01:27:53 CET 2010


No it isn't strange. Please read:

?options  digits
?print.default   

and then print the results with more digits.


Bert Gunter
Genentech Nonclinical Biostatistics
 
 
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Len Vir
Sent: Thursday, January 28, 2010 4:17 PM
To: R-help at r-project.org
Subject: Re: [R] Large integers in R

Hi!

That is somewhat strange.


B'R>2^100

[1] 1.267651e+30

B'R> x <- 2^50

B'R>  y <- x + 1

B'R>  y-x

[1] 1

B'R>x

[1] 1.1259e+15

B'R>x+1

[1] 1.1259e+15



len





From: Duncan Murdoch [murdoch at stats.uwo.ca]
Sent: Tuesday, January 26, 2010 4:09 PM
To: Blanford, Glenn
Cc: r-help at R-project.org
Subject: Re: [R] large integers in R

On 26/01/2010 3:25 PM, Blanford, Glenn wrote:
> Has there been any update on R's handling large integers greater than 10^9
(between 10^9 and 4x10^9) ?
>
> as.integer() in R 2.9.2 lists this as a restriction but doesnt list the
actual limit or cause, nor if anyone was looking at fixing it.

Integers in R are 4 byte signed integers, so the upper limit is 2^31-1.
 That's not likely to change soon.

The double type in R can hold exact integer values up to around 2^52.
So for example calculations like this work fine:

 > x <- 2^50
 > y <- x + 1
 > y-x
[1] 1

Just don't ask R to put those values into a 4 byte integer, they won't fit:

 > as.integer(c(x,y))
[1] NA NA
Warning message:
NAs introduced by coercion

Duncan Murdoch

	[[alternative HTML version deleted]]



More information about the R-help mailing list