Beginning with R

The total length of the videos in this section is approximately 11 minutes.


You can also view all the videos in this section at the YouTube playlist linked here.

Each of you will entire this course with different experience with R and with programming in general. Many of you will be entirely new to programming, and that's fine and expected. Many of you took a previous course that was taught in R, and this course is designed for you, too. 

If you are completely new to R, you should expect to spend some extra time on these initial R modules. You aren't expected to memorize every command when you see it for the first time, but making sure you understand these first modules will give you a strong foundation as you go forward.

If you are experienced in R, you may want to watch these initial R videos at double-speed and move through them more quickly. Don't skip anything, however, as there are likely certain commands you haven't see before this course that I will expect you to be familiar with as we go forward.

Ready to get started with R? First, let's get motivated.

After skimming that post, let's move on to the first video.

Downloading R (and perhaps RStudio)

BeginningR.1.Hires.mp4

Follow the instructions to download R. You may choose to also download RStudio.

RStudio arranges R so that your screen is divided into areas for code, output, plots, directories, etc. Most people prefer to use RStudio, though I personally don't use it regularly. 

PC users must use RStudio, as the default format of R on a PC lacks key features.

Mac users, feel free to try RStudio - you may find the layout helpful. However, the default format of R on a mac is workable and preferred by some (like me).

If you are using RStudio, you should open RStudio each time you want to access R. 

If you run into trouble with the download or installation, just ask for help.

R as a calculator

BeginningR.2.Calc.mp4

Question 1: Consider the following three lines of code:

Number1 <- 2

Number2 <- 3

Number1 ^ Number2

If you type those lines into the R Console, what will be printed?

Please type your answer into the lecture survey and then uncover the explanation below before moving on.

Show answer

8. The "^" symbol creates exponents.

Open R, and spend five or so minutes entering commands as you saw in the video above. 

Explore both R's use as a calculator and naming objects, printing out those objects' values, and using the object names to perform calculations (as in the problem above).

If you obtain an error, see if you can figure out how to correct it. If you can't figure out why a particular command is not working, ask!

Tip: If you press the up arrow when your cursor is in the R Console, the previous command will appear again. If you press the up arrow twice, the command before that will appear; etc.

Code files

BeginningR.3.CodeFiles.mp4

Question 2: Why record commands in a code file instead of typing directly into the R Console?

Show answer

You will have a record of your work and can reproduce it. You will be able to rerun your code easily if you need to make a small change or perform a similar analysis on a new data set. You can insert comments to organize and annotate your work. Also, you and others can collaborate on code, and you can provide it to explain your work to your audience (such as your instructors, but also future collaborators, colleagues, or the audience for your research).

Note, too, that you should not be copy-pasting code from code file to console. Instead, highlight lines in your code file and type command-return (on a mac) or control-enter (on a PC) to send those lines to the console.


R code files end with the extension ".R". Don't try to open them with a regular text editor. Instead, open the code file in R. With R open, you can either double-click on the file to open it or use File>Open Document. Make sure you know the difference between the R code file (where you should type commands and which you save and share with others) and the R console (where you run your code and see the output).

During this tutorial you learned:


Operators and functions in review:

<-, = 

+, -, *, /, ^

sqrt()