Skip to content

Instantly share code, notes, and snippets.

View sinarueeger's full-sized avatar

Sina Rüeger sinarueeger

View GitHub Profile
@hturner
hturner / integer_typing.R
Created January 22, 2020 16:19
Some examples of where explicitly using an integer scalar/vector is more efficient in R. Often the difference in a single operation is quite small, but if repeatedly using integer values in a script using explicit typing can be an easy way to gain speed.
library(microbenchmark)
# Examples where explictly typing with "L" is more efficient
## create a reasonably large matrix
r <- 5000
c <- 100
ints <- sample(0:10, r*c, replace = TRUE)
M <- matrix(ints, nr = r, nc = c)