Rstudio and R output different outputs

In Rstudio (using R 3.1.1), when I run this,

length(unique(sort(c(outer(2:100,2:100,"^"))))) # 9220 

In R 3.1.1, when I run this,

 length(unique(sort(c(outer(2:100,2:100,"^"))))) # 9183 

(correct exit - 9183)

I can’t understand why ... help is much appreciated

+8
r rstudio unique
source share
1 answer

As David Arenburg notes, this is the difference between 32-bit and 64-bit versions of R, at least on Windows machines. Presumably, some rounding error is involved. Interestingly, a 32-bit R receives a response correctly, while a 64-bit R detects too many unique numbers.

First, to confirm that 9183 indeed the correct answer, I used the gmp package (a wrapper for the GMP C Multiple Precision Arithmetic Library), which provides results that are not subject to rounding errors:

 library(gmp) x <- as.bigz(2:100) length(unique(do.call(c, sapply(x, function(X) x^X)))) [1] 9183 

Here are the results of my 32 bit R:

 length(unique(sort(c(outer(2:100,2:100,"^"))))) # [1] 9183 R.version[1:7] _ # platform i386-w64-mingw32 # arch i386 # os mingw32 # system i386, mingw32 # status # major 3 # minor 1.2 

And here are the results of my 64-bit R:

 length(unique(sort(c(outer(2:100,2:100,"^"))))) # [1] 9220 R.version[1:7] # platform x86_64-w64-mingw32 # arch x86_64 # os mingw32 # system x86_64, mingw32 # status # major 3 # minor 1.2 
+3
source share

All Articles