This lecture introduces how to apply functions in R programming, focusing on writing custom functions and using loops to repeat code segments. The lecture uses the example of a vote counting program to illustrate function creation, including defining function names, arguments, and bodies. It explains scope, wherein objects defined inside a function are not accessible outside it. The lecture also addresses error handling, demonstrating how to catch and manage non-numeric inputs using conditionals and the `suppressWarnings` function. Different types of loops—repeat, while, and for—are explained with examples, such as simulating squeezing a duck. The lecture concludes by applying these concepts to tabulating data, using for loops and the `apply` function for functional programming.
Sign in to continue reading, translating and more.
Continue