R Week: Fundamental Data Tasks in R by Eric Einspruch

Hi, I’m Eric Einspruch, Principal of ELE Consulting, LLC. R has been my primary data analysis tool for the past few years. Once you have installed R and a graphical user interface such as RStudio, it’s time to get to work.

Before you start, you need to install the packages that you want to use. Packages need to be installed only once onto your computer (though they occasionally need to be updated), but they need to be loaded each time you start an R session. One way to install packages is from within RStudio: from the “Tools” pull-down menu, select “Install Packages…”, then enter the name of the package you want to install (e.g., “tidyverse”), and finally click the “Install” button.

R is amazing not only in how many things it can do, but also in how many ways it can do things. R is very flexible, but that flexibility can sometimes make it difficult to know where or how to start with a task at hand. To help you get up and running, I have prepared some R code and an accompanying hypothetical data set that will introduce you to some fundamental data tasks. In particular, note in the code (you can download these files here):

  1. Use of “#” to insert comments into the code,
  2. Use of “library” to load packages that the program uses,
  3. Use of the assignment operator “<-” to create R objects, and
  4. Different ways of referencing a variable depending on whether you are using a Base R approach (look for the “$”) or a Tidyverse approach (look for the “%>%”, which is called the “pipe” and which is read as “… and then …”).

Hot Tip: Learn to work using both Base R and Tidyverse approaches. There are things that R can do that require one approach or the other, and you will want to be able to take advantage of both. Also, you may need to be flexible in determining which approach to use when working on R code with others.

Hot Tip: Learn the layered grammar of graphics. Understanding the grammar will vastly increase your ability to create the data visualizations you imagine (using, for example, the ggplot2 package).

Hot Tip: Use reference guides. The R for Data Science book is a very good reference guide. You may also want to keep one or more cheat sheets nearby. Many cheat sheets can be accessed through RStudio.

Lesson Learned: Learning R is similar to learning anything else new: regular practice leads to proficiency, take a break when you need to, and remember to have fun.

The American Evaluation Association is celebrating R Week with our R-forward colleagues who have contributed all of this week’s aea365 posts. Do you have questions, concerns, kudos, or content to extend this aea365 contribution? Please add them in the comments section for this post on the aea365 webpage so that we may enrich our community of practice. Would you like to submit an aea365 Tip? Please send a note of interest to aea365@eval.org. aea365 is sponsored by the American Evaluation Association and provides a Tip-a-Day by and for evaluators.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.