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*

17
  • 1
    Very cohesive summary. Just a few notes: (1) C knows how to handle "data.frame"s, since they are "list"s with attributes; it's that colMeans etc. that are built to handle only matrices. (2) I'm a bit confused by your third category; I can't tell what -exaclty- you're referring to. (3) Since you're referring specifically to lapply, I believe it doesn't make a difference between "[<-" in R and C; they both pre-allocate a "list" (an SEXP) and fill it in each iteration (SET_VECTOR_ELT in C), unless I'm missing your point. Commented Mar 12, 2015 at 13:33
  • 2
    I get your point about do.call in that it builts a function call in the C environmen and just evaluates it; although I'm having a hard time to compare it to looping or vectorization since it does a different thing. You're, actually, right about accessing and assigning differences between C and R, although both stay at the microsecond level and don't affect the result the rerult hugely, since the costly is the iterative R function call (compare R_loop and R_lapply in my answer). (I'll edit your post with a benchmark; I hope you, still, won't mind) Commented Mar 12, 2015 at 14:44
  • 2
    I'm not trying to disagree---and I'm confused, honestly, about what you're disagreeing with. My earlier comment could have been worded better. I'm trying refine the terminology being used because the term "vectorization" has two definitions that are often conflated. I don't think this is arguable. Burns and you seem to want to use it only in the sense of implementation, but Hadley and many R-Core members (taking Vectorize() as an example) use it in the UI sense too. I think that much of the disagreement in this thread is caused by using one term for two separate-but-related concepts. Commented Mar 14, 2015 at 20:33
  • 3
    @DavidArenburg and is that not vectorization in a UI sense, regardless of whether there's a for loop in R or C underneath? Commented Mar 15, 2015 at 2:59
  • 2
    @DavidArenburg, Gregor, I think the confusion is between "code vectorisation" and "vectorised functions". In R, the usage seems inclined towards the latter. "Code vectorisation" describes operating on a vector of length 'k' in the same instruction. Wrapping a fn. around loopy code results in "vectorised functions" (yes, it doesn't make sense and is confusing, I agree, better would be loop hiding or vector i/p functions) and need not have anything to do with code vectorisation. In R, apply would be a vectorised function, but it doesn't vectorise your code, rather operates on vectors. Commented Mar 16, 2015 at 17:25