If we want to multiply of elements of a list by a constant, we can do so with lapply. However, I have observed that defining the function to be applied in-line is almost twice faster than specifying "*" as the function to be applied:
library(microbenchmark)
microbenchmark::microbenchmark(x=lapply(X=list(a=c(1,2,3)), FUN=function(x) x*1000), y=lapply(X=list(a=c(1,2,3)), "*", 1000), times = 10000)
This gives me a median of around 1100 nanoseconds for the first expression, and around 1900 nanoseconds for the second one.
Any ideas why this could be happening?