Created
February 6, 2011 09:24
-
-
Save vsbuffalo/813253 to your computer and use it in GitHub Desktop.
Give R hints when it's working with integers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you have a long vector of integers to compare against an integer literal, | |
# specify that the numerical literal is an integer rather than letting | |
# R coerce the entire vector to doubles. | |
x <- as.integer(floor(rnorm(1000000, 0, 1000))) | |
system.time(x < 0) | |
# user system elapsed | |
# 0.014 0.000 0.014 | |
system.time(x < 0L) | |
# user system elapsed | |
# 0.003 0.000 0.004 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment