The tutorial you need to maximize your use of vectors in R (CC273)

แชร์
ฝัง

ความคิดเห็น • 19

  • @eric13hill
    @eric13hill 5 หลายเดือนก่อน +5

    I really enjoy this type of R training. Thanks.

    • @Riffomonas
      @Riffomonas  5 หลายเดือนก่อน

      Awesome to hear - thanks!

  • @joshstat8114
    @joshstat8114 18 วันที่ผ่านมา +1

    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.

  • @jushtmoment1571
    @jushtmoment1571 5 หลายเดือนก่อน +3

    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.

    • @Riffomonas
      @Riffomonas  5 หลายเดือนก่อน

      oh my - great catch! lapply without unlist was 3515064, with unlist was 3668230 - not much of a difference

    • @jushtmoment1571
      @jushtmoment1571 5 หลายเดือนก่อน

      @@Riffomonas Makes sense. Dispels the for loop myth for sure!

  • @NATS7599
    @NATS7599 5 หลายเดือนก่อน +1

    Another great tutorial!! Thank you for all your time and effort creating these gems of wisdom. 🙏

    • @Riffomonas
      @Riffomonas  5 หลายเดือนก่อน

      My pleasure - thanks for watching!

  • @haraldurkarlsson1147
    @haraldurkarlsson1147 5 หลายเดือนก่อน

    Interesting.

  •  5 หลายเดือนก่อน

    Interesting comparisons, and trying to understand the differences.

    • @Riffomonas
      @Riffomonas  5 หลายเดือนก่อน +1

      Thanks for watching - let me know if you have any questions

  • @FlippieCoetser
    @FlippieCoetser 5 หลายเดือนก่อน

    Another version: 1:x |> (\(x) x^2)() . Note: %>% not equal |>

    • @Riffomonas
      @Riffomonas  5 หลายเดือนก่อน

      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?

    • @FlippieCoetser
      @FlippieCoetser 5 หลายเดือนก่อน +1

      @@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.

    • @Riffomonas
      @Riffomonas  5 หลายเดือนก่อน

      @@FlippieCoetser Thanks!