Loop in r5/31/2023 ![]() They need your expert opinion to give them a quick conclusion about whether a myth is “plausible”, “busted” or “confirmed”. Every day, the hosts Adam and Jamie come to you with data about different myths that were tested. You are an intern on the show “ Mythbusters“. You can now combine all that you have learned to write functions! Let’s take one final example. ![]() (reminder: ‘vec’ is the vector ‘vec’ without the k-th element) ![]() – Compare the runtime with “difference()” for a vector containing 100,000 values (e.g. – Create a function “difference2()” that computes the interval between successive events, such as in “interval = vec – vec”, but without using loops – Create a function “difference()” that computes the interval between successive events, such as in “interval = vec – vec” (Yes, I know, in this specific case, we could simply write “bigdata3 <- bigdata1 + bigdata2”, but that wouldn’t illustrate what I’m talking about now, would it?!) Exercise 5.3 The most versatile kind of loop is specified with the instruction “ for (A in B) One way of doing that in R is through loops. The goal of a function is often to make our life easier when repetitive and/or complex operations have to be done.
0 Comments
Leave a Reply. |