Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 10
    Great point about the costs of converting the data.frame to a matrix, and thanks for providing benchmarks. Commented Mar 11, 2015 at 14:12
  • That is a very nice answer, though I wasn't able to compile your all_C and C_and_R functions. I also found in the documentations of compiler::cmpfun an old R version of lapply which contains an actual R for loop, I'm starting to suspect that Burns was referring to that old version which was vectorised since then and this is the actual answer to my question.... Commented Mar 11, 2015 at 20:10
  • @DavidArenburg : Benchmarking la1 from ?compiler::cmpfun seems, still, to yield same efficiency with all but all_C functions. I guess, it -indeed- comes to be a matter of definition; is "vectorised" meaning any function that accepts not only scalars, any function that has C code, any function that uses computations in C only? Commented Mar 11, 2015 at 22:33
  • 1
    I guess all functions in R have C code in them, simply because everything in R is a function (which had to be written in some language). So basically, if I understand it right, you are saying that lapply isn't vectorized simply because it's evaluating an R function in each iteration wihin its C code? Commented Mar 12, 2015 at 6:50
  • 6
    @DavidArenburg : If I must define "vectorization" in some way, I guess, I would choose a linguistic approach; i.e. a function that accepts and knows how to handle a "vector", whether it's fast, slow, written in C, in R or anything else. In R, the importance of vectorisation is in that many functions are written in C and handle vectors while in other languages users would , usually, loop over the input to -e.g.- find the mean. That makes vectorisation to relate, indirectly, with speed, efficiency, safety, and robustness. Commented Mar 12, 2015 at 13:12