Skip to content

Instantly share code, notes, and snippets.

@vsbuffalo
Created February 6, 2011 09:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vsbuffalo/813253 to your computer and use it in GitHub Desktop.
Save vsbuffalo/813253 to your computer and use it in GitHub Desktop.
Give R hints when it's working with integers
# 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