![]() It permits you to write horrible code that is hard to read and debug.While for is definitely the mostįlexible of the looping options, we suggest you avoid it wherever you can in favor of functions in plyr and the like, for the following two reasons: Like basic, python, perl, C, C++ or MATLAB. That's because they are already familiar with these other languages, When you mention looping, many people immediately reach for for. In what years did the condition life expectancy > 40 occur? Repeating operations For loops - when the order of operation is important Hint: use the function subset within your function to subset the data - type ?subset on the console for examples. Using the gapminder dataset, create a function called subsetAndEvaluateLifeExp that subsets the data to a given year and continent, and return the average population size among countries if their life expectancy are all above 40 years, otherwise return a message saying what countries had their life expectancy below 40 years. We could have also created the different statements with the function all instead of any. ![]() The same idea works for the function warning. This function is widely used in what's known as defensive programming - if you anticipate a potential problem in your data manipulation/analysis within a function, the function can stop if this certain problem occurs and print an informative error message. The reason for that is because the function stop was evaluated.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |