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
(the correct output is 9183)
I can't figure out why... help is greatly appreciated
In simple words: In console, you can run your R commands. In terminal, you can access your system shell.
You can also save the entire R console screen within the GUI by clicking on "Save to File..." under the menu "File." This saves the commands and the output to a text file, exactly as you see them on the screen.
RStudio supports multiple terminal sessions. To start another terminal session, use the New Terminal command on the Terminal dropdown menu, or Alt+Shift+R.
RStudio is an integrated development environment (IDE) for R. It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, debugging and workspace management.
As David Arenburg notes, this is a difference between 32-bit and 64-bit R versions, at least on Windows machines. Presumably, some sort of rounding error is involved. Interestingly, it is the 32-bit R gets the answer right, whereas the 64-bit R finds too many unique numbers.
First to confirm that 9183
is indeed the correct answer, I used the gmp
package (a wrapper for the C multiple precision arithmetic library GMP), 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 from 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 from 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With