Using R for the 1st Time

Once you have downloaded and installed R and RStudio, you are ready to start playing with this powerful statistical computing environment.

Importantly, R is a program that runs in a text-based environment called the R Console. Working in this type of environment may be unfamiliar at first, as graphically-based programs are so much more common. R is at its heart a programming language. Specifically, R is an interpreted language -- which means that you type instructions for what R is to do in this console, and then R interpets and executes your instructions, and then returns any results.

When programming, it is often convenient to have quick and simultaneous access to lots of different things: a text editor, the console, information about variables created, recent plots, packages installed, etc. This is normally accomplished by employing an integrated development environment (or IDE). An IDE is a second piece of software that serves as a front end for the language. RStudio is one such IDE for R. Essentially, you can run RStudio and do all your work there, and it will take care of invoking R in the background to do your bidding.

When you start RStudio, you will be presented some number of windows -- the R Console will be one of these. While you could do everything from that console, you will probably find it advantageous to work inside an R script whenever you have more than a line or two to type. Select "File → New File → R Script" from the menu. This should create a new script window in which you can type.

In this new script window, type the following:

Then, highlight all that you just typed and click the "Run" button near the top of the script window. This sends all of the code you just typed to the RConsole, executes it, and shows any output it produced in the R Console window as well.

Alternatively, you can simply type the above directly after the "$\gt$" prompt in the R Console and then hit return.

Whichever way you chose to execute the code, if things went well you should see the following in your R Console window, showing that the average (i.e., "mean") of the numbers 1 through 6 is 3.5.

> mean(c(1,2,3,4,5,6))
[1] 3.5
Congratulations, you just did your first calculation with R!