Using R

Tutorials and examples


Kevin Potter (updated 2022/06/25)

In the following, I provide a series of examples of using R in applied settings, with a focus on applications for clinical/psychiatric research and data processing. These examples are meant to be intuitive and accessible, for people without much experience in programming.

Sections

Why R?

R is a programming language with a focus on data processing, data visualization, and statistical analyses. If you intend on regularly processing data, especially with the end-goal of performing statistical analyses (or preparing data for someone else to run statistical analyses), R is designed specifically to aid in this goal. Writing data processing, visualization, and analysis scripts in R can help, for example, with:

  1. Ensuring reproducibility (scripts can be easily rerun and annotated with notes);
  2. Avoiding common transcription/processing errors;
  3. Enabling portability and making it easier to share work with labmates;
  4. Providing a larger toolset for data-checking.

Additionally, R has simple and intuitive means for extensions via R packages, allowing users to download additional software specific to their current problem. As a starting place for learning how to program, R can be easier then other languages (e.g., Java or C++), especially because it has a large, diverse user base and plenty of resources built around non-programmers and applied examples.

Resources for R

R is a popular language, and there are a great many books and online tutorials written on R. Below are some example links:

  • A R cheat sheet, a PDF file listing R commands (useful to consult if you are trying to remember a standard R command).
  • Learning Statistics with R, an online book by Danielle Navarro for teaching introductory statistics to psychology students.
  • Advanced R, a online book by Hadley Wickham (aimed at intermediate to advanced users of R, useful to consult if you want more in-depth knowledge about how R works and how to best use it).
  • Additional links provided by the Association for Psychological Science.