Learning to Work With R

Below are some great tutorials that are freely available online and are great introductory tools for getting you started on your journey to R mastery.

1) Getting Started with R

The R Website (free)
This is the website where you download R. Many of the packages you will want to use are available here. 

The RStudio Website (free)
This is a great interface that makes R more accessible and user-friendly. However, note that you need to download R before you can download RStudio.

2) Learning the Basics

Learning Statistics with R by Danielle Navarro (free)
We can’t speak highly enough of this website. Built around a free textbook written for college undergrads, the website includes the slides, audio, and exercises from a 5-hour workshop. Danielle makes learning R simple and entertaining. She also covers basic statistics in the textbook, so if you’re looking for a primer on t-test and regression models, start here.

YaRrr! The Pirate’s Guide to R by Nathaniel Phillips (free)
If you ever feel ambitious enough to learn R and Pirate simultaneously, then this is the resource for you! This PDF contains all of the resources for the fundamentals of getting started with R, for both you and your fellow pirates. We love this resource because it covers the basics of R programming in a clear and funny way.

The Art of R Programming by Norman Matloff
This is a great (textbook) resource for getting started with R. Matloff goes into incredible detail when describing what variables are, what you can do with them, etc. He also covers some programming basics, like looping. This is a great and accessible way to learn conceptually how R works under the hood.

DataCamp: Introduction to R (free)
This website walks you through the basics of working with vectors, matrices, factors, data frames, and lists. This interface is great because you don’t need to download any software. The focus is on learning the syntax of the language with worrying about setting up your environment.

swirl (free)
Swirl is an R package that makes it fun and easy to learn R programming and data science. Designed for the R newbie, this interactive course walks users through each of the steps to get acquainted with R. The various interactive courses range from beginner (e.g., basics of R programming, statistics and data visualization, basic statistics boot camp) to more intermediate and advanced topics (e.g., regression, manipulating data, statistical inference). This tutorial is incredibly flexible, since you can pick and choose which courses you would like to take that best suits your needs.

Coursera: R Programming (free)
This is a free online course to help you learn how to program in R and use R for effective data analysis. This covers practical issues in statistical computing which includes programming in R, reading data into R, accessing R packages, writing R functions, debugging, profiling R code, and organizing and commenting R code. This is based on the swirl package (see above), and is taught by instructors at the Johns Hopkins Bloomberg School of Public Health.

R Programming for Data Science
This course was developed by the Johns Hopkins Data Science Specialization group. You can purchase just the book, the book plus code and data to practice with (always recommended), or the book, data and code, and lecture videos.

R Tutorials by William B. King (free)
This is a set of tutorials for getting started with doing statistics with your data in R once you feel comfortable with the R environment.

R for Cats (free)
Yes, this is very silly. But it covers the basics of objects and functions quickly, efficiently, and complete with cat gifs.

3) Advanced Techniques and Statistics

r4stats.com (free)
This website is designed by Bob Muenchen specifically for SAS and SPSS users. It includes downloads, examples and a free version of his textbook (under the Book tab in the menu).

R Tutorial (free)
This is super useful for walking you through more complex analyses such as hierarchical linear modeling and support vector machines, to name a few.

Personality Project (free)
APS Fellow William Revelle, the creator of the psych package, gives extensive workshops on how to use R around the world (including workshops at the Association for Research in Personality [ARP] and at the APS Annual Convention). This website includes slides from his past workshops and pages describing how to manipulate data, display data, and perform some multivariate analysis. There is also a page of useful commands which you can bookmark for easy reference.

Cookbook for R (free)
If one of your main goals is to create stunning graphics, you should be using the ggplot2 package, created by Hadley Wickham. One of Wickham’s former graduate students wrote a book called “R Graphics Cookbook,” and then kindly posted the book online for free at this website. He covers many nongraphic codes, including numbers, strings, formulas, data input, output, and manipulation, and statistical analyses. The book and website are in the forms of problems and answers, which makes it very relatable. There is also a lot of commenting in the code, which allows you to understand what the code is doing.

R Psychologist (free)
This is a blog by Kristoffer Magnusson, a clinical PhD student in Sweden. Magnusson talks about methodology and supports his points with simulations and graphics in R code. This is a wonderful resource for teachers because it includes simulations and interactive graphics which demonstrate correlations, NHST, confidence intervals, etc.

R-bloggers (free)
Now that you have worked with R for so long that you have become a nerd, and you want to do nerdy things and talk about R with nerdy R people — this is the place for you. Hundreds of R users post to this website. It is a great place to figure out how to do that one obscure thing you need to do, or learn a new technique or see cool graphs.

4) Communicating your R Analyses to Others

Worried about producing reproducible research analyses in R? Here are some great tools to help you create dynamic documents to enable others to reproduce your results! All are pretty easy to use with RStudio, so it is just matter of personal preference for which package you choose to use.

R Markdown (free)
R Markdown is an authoring format that enables users to easily create dynamic documents and reports from R. It is in an easy-to-write plain text format, combined with embedded R code chunks that can be run in your document. R Markdown can be used to generate documents in either PDF, Microsoft Word documents, or HTML format. If you want to get really fancy, you can combine R Markdown with other programs to create interactive documents, administrative dashboards, presentations, and even publish your own books.

Sweave is a tool that allows you to embed R code in LaTeX documents. When you run Sweave, your data analysis output (tables, graphs, etc.) are created on the fly and inserted into a final LaTeX document. NOTE: This tool requires latex, which you must install separately.

Knitr is a package that combines Sweave and other packages to create a dynamic report. For the programmers out there, you can consider this as Sweave++. NOTE: This tool also requires latex, which you must install separately.

5) A Few of “R” Favorite Things

This handout would not be complete without listing some of our favorite R packages. Despite the diversity of applications that R can be used for, we have converged on some packages that we believe are globally relevant to all psychologists and useRs. We’ve listed them in the table below, along with some relevant tutorials and/or online resources. However, we highly recommend using the internet to get more up-to-date information detailed information about these packages.

Table 1: Some of our favorite R packages. Some of these tutorials are hosted on websites with many more R help pages. We particularly like the UCLA website (which is part of their Institute for Digital Research and Education) because they have clear and helpful walkthroughs, and the StatsMethods website, which includes code for many basic statistics. We encourage you to click around on these sites and see what else they have to offer.

Sara and Debbie’s R Tutorials (free)
If you are interested in our personal take on R, you can view slides from our presentation below. (Our introductory workshop is heavily influenced Dan Navarro’s Introductory Workshop in R, which we also highly recommend. See the first link in the “learning the basics” section for reference.) This annual two-day workshop is held for the incoming first year graduate students in the psychological and brain sciences at the University of Washington in St. Louis. In addition to the annual workshop, we hold various “mini-workshops” in which we cover how to do more advanced topics in R and some of the packages listed above.

If you have any questions, please don’t hesitate to reach out to us! We are friendly, and we love to geek out about R.

Sara Weston

Debbie Yee