For loops in R: a tutorial on how to simplify your code without compromising performance (CC173)
ฝัง
- เผยแพร่เมื่อ 28 มิ.ย. 2024
- For loops get a bad rap in R. In this tutorial, I'll share they syntax for writing a for loop and how we can use a for loop to simplify our code without compromising the performance of our code. This is part of a series of videos demonstrating how to functions from base R to make these data compatible with tools from the tidyverse
You can find my blog post for this episode at www.riffomonas.org/code_club/....
The data were generated in our Kozich et al. 2013 paper (doi.org/10.1128/AEM.01043-13) using samples from the Schloss et al. 2012 paper (doi.org/10.4161/gmic.21008).
#matrix #baseR #R #Rstats
Want more practice on the concepts covered in Code Club? You can sign up for my weekly newsletter at shop.riffomonas.org/youtube to get practice problems, tips, and insights.
If you're interested in taking an upcoming 3 day R workshop be sure to check out our schedule at riffomonas.org/workshops/
You can also find complete tutorials for learning R with the tidyverse using...
Microbial ecology data: www.riffomonas.org/minimalR/
General data: www.riffomonas.org/generalR/
0:00 Creating DRY code with for loops
2:01 Syntax to create a for loop
5:06 Finding patterns in repeated code
10:17 Writing for loop to create distance matrix
11:20 Demonstrating the value of DRY code
13:30 Overcoming concerns about for loops - วิทยาศาสตร์และเทคโนโลยี
Thanks Pat. You're doing a great service for experienced and new coders alike.
Hey Marc - my pleasure, keep watching!
Thanks Pat, I have enjoyed with your series of using R base functions. It will be useful for us if you record another episode about nested loops in R
My pleasure! Let me see what I can do. I have some older videos where I use map functions to replace loops. Thankfully the ability to vectorize functions like we did within this loop prevent a lot of need for nested loops
helpful video