In addition to writing this piece, author Diego Catalán Molina led an OPEN event on 12 May 2021 about data analysis tips and tricks using R. Diego holds a PhD in Human Development at the University of California (UC), Davis, where he studied how, when, and for whom socioemotional school interventions work. He previously worked in Chile as a school counselor at a low income school, an advisor to school counselors and psychologists at network of charter schools, and an evaluator for the national agency that monitors education quality across the country. He has served on the OPEN leadership team since 2020.
Have you started using R and found obstacles to efficiently move from running analyses to reporting results? I know I have...
I started using R around 3 years ago. The first few months, I was frustrated often because I couldn't even read and manipulate data efficiently, when the REAL work was analyzing the data. And when I had analyzed it, I didn't know how to transfer the results efficiently into my documents and presentations.
Here’s what I tried:
- Manually type results into a word document--it’s really easy to make mistakes doing this!
- Copying and pasting the results from the console to a word document or a spreadsheet: This is a terrible strategy because the formatting of the results is not the same once pasted, and it’s really difficult to work this way when you have to re-run your analyses multiple times!
Looking back, I think most of my confusion had to do with me not understanding some of the core ideas behind doing data analysis in R.
Core ideas
After doing research and evaluation in R for almost 3 years, I realized there were a few principles or core ideas behind doing data analysis in R. On May 12th, I shared the following two ideas with OPEN members and friends:
-
Running analyses is like lazy shopping at the grocery store.
-
You need to tidy up your stuff to avoid wasting time.
Lazy shopping
You don’t realize it in the beginning, but running analyses in R is like throwing all kinds of groceries into a shopping cart.
In R language, your shopping cart is called a list. A list is an object that contains smaller objects within it, so it's just a "container". When you run any analysis, R will fill your list with the results of your analyses (and other stuff too).
If you are running analyses in R, you were probably taught to see the results by using functions like summary. However, this is the most inefficient way to use your results if you want to put them in a presentation or document.
Tidy up your mess
If you want to use your results efficiently, you need to learn how to clean up the mess that is the list in which these results live.
Here are simple steps to use your results more efficiently:
-
Think about the numbers or information you want to transfer to your presentation or document.
- Try finding that piece of information inside the list. You can do this by clicking on the magnifying glass icon in your Global Environment.
- Once you find it, use the symbol $ to "grab" the piece of information and do whatever you want with it (e.g., create an object or embed it directly into your RMarkdown document). Do you need some examples? Check this out! FYI, they use the term subsetting to refer to the action of "grabbing" information from the list.
Do you want to learn more about efficient analyses in R and beyond?
Let's chat!