I think I read it from Hadley Wickham's advance R book where he said that you still can't avoid using for loop and he didn't recommend using apply family functions or something just to get faster loops, I don't really remember.
Great video! For the vector_lapply experiment at 18:49 it looks like you ran the experiment in sapply it self. Curious to see if there is an appreciable difference with lapply followed by unlist.
Interesting! This particular syntax for an anonymous function in a pipeline is new to me. Just to be clear, it's passing all of 1:x into the function, kind of like my vector_colon function. It is not passing one value at a time like lapply/sapply/map - right?
@@RiffomonasSince R is vector-based you can pass the vector directly to a function without the need to use lapply/sapply/map etc. To answer your question, I believe all of the 1:x values are passed in at the same time, but I am not 100% sure. Normally, I would define and store the function in a separate variable: `calculation ` and also the new shorthand syntax for anonymous function declaration: `\(){}`, the code can be condensed a lot, as I have shown. Also, I believe the %>% is from a package while |> is native, which may also contribute to differences in performance. Lastly, there is a difference in data types between c(1, 2,3) and 1:3, which might also explain the difference in performance. Both 1:3 and c(1,2,3) return a vector BUT of different types: c(1,2,3) returns typeof double while 1:3 returns typeof integer. I am of the opinion that R is the most flexible language out there. I absolutely love these kind of videos. They are so insightful! Thanks for the effort you put into making them. I look forward to the next one.
I really enjoy this type of R training. Thanks.
Awesome to hear - thanks!
Another great tutorial!! Thank you for all your time and effort creating these gems of wisdom. 🙏
My pleasure - thanks for watching!
I think I read it from Hadley Wickham's advance R book where he said that you still can't avoid using for loop and he didn't recommend using apply family functions or something just to get faster loops, I don't really remember.
Great video!
For the vector_lapply experiment at 18:49 it looks like you ran the experiment in sapply it self. Curious to see if there is an appreciable difference with lapply followed by unlist.
oh my - great catch! lapply without unlist was 3515064, with unlist was 3668230 - not much of a difference
@@Riffomonas Makes sense. Dispels the for loop myth for sure!
Interesting comparisons, and trying to understand the differences.
Thanks for watching - let me know if you have any questions
Interesting.
Another version: 1:x |> (\(x) x^2)() . Note: %>% not equal |>
Interesting! This particular syntax for an anonymous function in a pipeline is new to me. Just to be clear, it's passing all of 1:x into the function, kind of like my vector_colon function. It is not passing one value at a time like lapply/sapply/map - right?
@@RiffomonasSince R is vector-based you can pass the vector directly to a function without the need to use lapply/sapply/map etc. To answer your question, I believe all of the 1:x values are passed in at the same time, but I am not 100% sure. Normally, I would define and store the function in a separate variable: `calculation ` and also the new shorthand syntax for anonymous function declaration: `\(){}`, the code can be condensed a lot, as I have shown. Also, I believe the %>% is from a package while |> is native, which may also contribute to differences in performance. Lastly, there is a difference in data types between c(1, 2,3) and 1:3, which might also explain the difference in performance. Both 1:3 and c(1,2,3) return a vector BUT of different types: c(1,2,3) returns typeof double while 1:3 returns typeof integer. I am of the opinion that R is the most flexible language out there. I absolutely love these kind of videos. They are so insightful! Thanks for the effort you put into making them. I look forward to the next one.
@@FlippieCoetser Thanks!