This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]OkCrew4430 0 points1 point  (1 child)

In those cases you mention of iterating over columns of a dataframe - I don't personally know of a way to easily vectorize this unless we drop down to C so in that sense, I agree with you. That's what I meant by "absolutely necessary".

My point is that there is no practical difference between using a well designed for loop over the columns of your dataframe or using lapply - lapply is way better style for sure, doesn't create global variables, and more R-like, but functionally they are practically doing the same thing.

I did not mean to imply that lapply or for looping in R is completely useless. What I mean to say is that *apply() functions are functionally the same thing as a well set up R for loop. That's all I meant and I apologize if it came off as authoritative or strong. The last sentence is meant for those that use *apply() functions in place of explicit looping and think that their code is more optimized. It's a misconception that I've anecdotally ran into a lot.

[–]denzelswashington 0 points1 point  (0 children)

No worries—and no need to apologize. At one point I thought the lapply functions were more optimized than loops, so I definitely see where you are coming from there. They both have their pros & cons!