1.1 Why programming?

Being able to easily repeat your own work is an excellent reason to learn a programming language like R or Python when trying to make sense out of data. If you create a script containing all the steps for analyzing your data, you can easily re-do all your work. Simply execute a single command to run your code, and the script does the rest. That’s true whether you’ve got a new, corrected data set or data that you receive regularly in the same basic format.

Do you receive monthly unemployment numbers that you process the same way? Daily arrest stats? Election results every year or two? Annual school test scores? Whatever it is you’re analyzing, if you script it once, odds are you’ll be well on your way to automating future analysis when the data changes.

But there are other advantages to using a script. This kind of workflow lets others check your work much more easily – what’s known as reproducible research in the research community – than if you give someone a spreadsheet with multiple formulas. Even if a formula is correct in one cell, how can they – or you – be sure it’s been properly copied and pasted? A script will run the same way each time it’s executed.

There are certainly plenty of errors you can make when writing code. But one thing you won’t have to worry about is whether you’ve copied and pasted or clicked and dragged properly (or used control-click instead of just click for certain types of advanced Excel formulas). And, someone else who’s reviewing your work won’t have to wonder either.

The good news: If you’ve written formulas in Excel, you’ve already done “programming” – just not on the command line, and not in a way that’s easy to repeat.

The command line can seem intimidating at first for those who are used to working in more of a graphical environment. But after some practice, chances are you’ll enjoy the power, flexibility, and what’s-my-code-doing transparency of programming. And if you download the recommended RStudio software for writing and running your R code, you’ll even have some benefits of a graphical user interface while creating your code.