Using R-Studio for the First 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 with a window with some number of panes inside it -- the R Console will be one of these. You can, if you wish, do everything from the console prompt in this pane (shown below):

However, you will instead likely 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, let's issue a command to find the mean (i.e., average) of a small set of values. 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.

You should see something like the following:

Notice how the command you just executed is printed again at the bottom of the window, in the console area, along with the corresponding output value (i.e., 3.5) directly below that. (Ignore the "[1]" that precedes it -- we'll talk more about that later.)

You can also simply type the "mean(c(1,2,3,4,5,6))" directly after the "$\gt$" prompt in the R Console and then hit return to the same end.

Congratulations, you just did your first calculation with R!