Automating repetitive tasks with loops and functions.
Many R users get into R programming from a statistics background rather than a programming/software engineering background, having previously used software such as SPSS, Excel etc. As such they may not have an understanding of some of the programming techniques that can be leveraged to improve code. This can include making the code more modular which in turn makes it easier to find and resolve bugs, but also can be used to automate repetitive tasks, such as producing tables and plots etc.
This short post in c ludes some of the basic programming techniques that can be used to improve the quality and maintainability of R scripts. This will also save you a whole lot of time if you are carrying out repetitive tasks that are only marginally different. We assume that you have a basic understanding of writing simple scripts in R.
Let’s start with a simple example. Let’s say we have some data from several different groups. In this case 3 animals (tigers, swans and badgers) and we have collected some data on relating to this (a score and value of some kind).