Introduction
R is perhaps the most powerful computer environment for data analysis that is currently available. R is both a computer language, that allows you to write instructions, and a program that responds to these instructions. R has core functionality to read and write files, manipulate and summarize data, run statistical tests and models, make fancy plots, and many more things like that. This core functionality is extended by hundreds of packages (plug-ins). Some of these packages provide more advanced generic functionality, others provide cutting-edge methods that are only used in highly specialized analysis.
Because of its versatility, R has become very popular across data analysts in many fields, from agronomy to bioinformatics, ecology, finance, geography, pharmacology and psychology. You can read about it in this article in Nature or in the New York Times. So you probably should learn R if you want to be good in data analysis, be a successful researcher, collaborate, get a high paying data science job, … If you are not that much into data analysis and visualization but want to learn programming for more general tasks, you may want to start with python instead.
This document provides a concise introduction to R. It emphasizes what you need to know to be able to use the language in any context. There is no fancy statistical analysis here. We just present the basics of the R language itself. We do not assume that you have done any computer programming before (and if that is the case, we do assume that you think it is about time you did). Experienced R users obviously need not read this. However, the material may be useful if you want to refresh your memory, if you have not used R much, or if you feel confused.
When using this resource, it is very important to follow Norman Matloff’s advice: “When in doubt, try it out!”. That is, test yourself. Copy the examples shown, and then make modifications to see if you can predict what will happen. Only then will you really understand what is going on. You are learning a language, and you will have to use it a lot to become good at it. So express yourself and accept that for a while you will be stumbling a lot and sometimes feel lost.
To work with R on your own computer, you need to download the program and install it. I recommend that you also install R-Studio. R-Studio is a separate program that makes R easier to use. Here is a video that shows how to work in R-Studio.
After having gone through the chapters presented here, you should could consult additional resources to learn R. It is very helpful to read several of these introductions to R while you use it in your work. Each time you will pick up new things, and feel accomplished about how much you already understand. There are many free resources on the web, including R for Beginners by Emmanuel Paradis and this tutorial by Kelly Black that is similar to the one you are reading now. Or consult this brief overview by Ross Ihaka (one of the originators of R) from his Information Visualization course. You can also consult the more formal “official” introduction or get a copy of Norman Matloff’s book The Art of R Programming.
There is also a lot of good stuff on rstatistics.net
If you want to take it easy, or perhaps learn about R while you commute on a packed train, you could watch some Google Developers videos.
If none of this appeals to you, and you already are experienced with R, or you have done a lot of programming with other languages, skip all of this and perhaps have a look at Hadley Wickham’s Advanced R.
Installing the R and R Studio software
Windows
Install R
Download the latest R installer (.exe) for Windows. Install the downloaded file as any other windows app.
Install RStudio
Now that R is installed, you need to download and install RStudio. First download the installer for Windows. Run the installer (.exe file) and follow the instructions.
Mac
Install R
First download the latest release (“R-version.pkg”) of R Save the .pkg file, double-click it to open, and follow the installation instructions. Now that R is installed, you need to download and install RStudio.
Install RStudio
First Download the the version for Mac. After downloading, double-click the file to open it, and then drag and drop it to your applications folder.
Linux
Install R
Go to this web page and open the folder based on your linux distribution and follow the instructions in the ‘readme’.
Install RStudio
It is difficult to provide a single guideline for different linux distributions. Please follow the general steps provided here and download the installer for the linux distribution you are using and install it.