The goal of this lab is to introduce you to R and RStudio, which you’ll be using throughout the course both to learn the statistical concepts discussed in the course and also to analyze real data and come to informed conclusions.
To clarify which is which:
Before we start, let’s get RStudio running.
There are two ways you can run R and RStudio:
That said, I don’t recommend trying to do your own R installation yet unless you have experience with it already
For today, even if you have R/RStudio installed on your machine, you should log in to the server so you know how to do so.
Here’s how to do it
cdawson
)passwd
at the terminalThis orientation will cover fundamental building blocks of R and RStudio: the interface, reading in data, and basic commands.
The panel in the upper right has tabs for your
The pane in the lower right has tabs for
The panel on the left is called the console. When you first launch RStudio, it shows what version of R that you’re running, etc.
Below that information is the prompt. As its name suggests, this prompt is really a request, namely a request for a command: a line of R code that tells the computer to do something.
Enter some simple arithmetic expressions like the following at the console and verify that the output is as expected. (Note that the asterisk represents multiplicationn and the slash is for division.)
Useful tip: When your cursor is at the console, you can use the up and down arrows to cycle through recently typed commands.
Each time you begin a new lab or assignment, you should create a new project so you can keep your work distinct from one assignment to the next.
stat209
. Click “Browse” and choose that directory as the home of your new project.R-orientation
. Type this name in the “Directory Name”. Avoid using spaces or special characters (such as punctuation) in directory names. For multiword names you can use CamelCase
, or separate words with-hyphens
or with_underscores
. Pick a convention and stick with it.Whenever you begin a new assignment, it is a good idea to create a new project. This will help keep things you did in a previous session from interfering with what you are trying to do in this session.
R is an open-source programming language, meaning that users can contribute packages that make our lives easier, and we can use them for free. We will use a handful of different packages that make doing modeling and the tasks related to modeling simpler.
Note that you can check to see which packages (and which versions) are installed by inspecting the Packages tab in the lower right panel of RStudio. Don’t install packages yourself on the server: This could result in two different versions being installed at once, causing you to see different behavior than others in the class
We will use a document format called RMarkdown that helps us keep our work better organized. It is basically like a Word document with some stripped down formatting capability, but with an important difference: you can embed R commands into your document in “code chunks”, which will be run and produce output when you “compile” your document.
This instruction document was created using RMarkdown.
markdown-tutorial.Rmd
in your stat213/originals/R-orientation
folder. This will cause the left-hand part of R Studio to split in half, the console moving to the bottom, and a new pane appearing in the upper left that has a tab showing the contents of the file.markdown-tutorial.Rmd
in your project directory (you will not be able to modify the original or any of the files in the originals
directory, which is read only)