Version March 2018
This script provides a concise introduction to the basic functionalities of R.
R (and for that matter any programming language) is hard to grasp at first. The learning curve is steep, but it does get easier. Moreover, there are a multitude of free resources available online that provide guidance and support to learn on your own.
Also disclaimer: I am law professor, not a programmer. So other resources will be better at teaching you how to program. However, if you are interested in learning how lawyers can use data science, and more specifically the R programming language, then keep on reading.
Setting up R and RStudio
To get started, you will need to download two applications. First, you will need to download the program R here. Second, you should also download the user-friendly interface for working with R called RStudio here.
A word on programming before we start. Programming is a bit like cooking using a recipe. The script is the recipe that you follow and the console is the stove you cook on. In other words, it is where you execute the code from your script.
Like cooking your favorite recipe, the script will ensure that you can execute the same code today, in a week or in a year. You don’t have to remember how you did it last time, instead, you just need to follow the steps in your script. Two consequences flow from this. First, whenever you make changes or try out new alternatives, write them in the script (or create a new script) and not in the console. Otherwise you risk losing the information how you did it. Second, make sure to make comments about your code to ensure that months from now you will be able to easily understand your work. This will make it easier to change your code or customize it to work with new data. In R, you comment with the “#” symbol as you will see below.
Now, we are ready to go.