R Basics 2

The total length of the videos in this section is approximately 27 minutes, but you will also spend time running and exploring R code on your own while completing this section. Remember that you can speed up the videos if you click on the settings icon, which might be an especially useful plan for those of you who have seen R before.

This module mentions some hypothesis testing concepts that you may or may not have been exposed to yet, depending on how you are ordering the modules. If you see an unfamiliar statistical concept in this discussion of code, don't worry - it is coming soon!

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

Please download the code file RBasics2.R from the google drive embedded below. As before, explore the code file a bit on your own before watching the videos and answering the questions in the lecture survey.

Logic

RBasics2.1.Logic Operators.mp4

Question 1: Consider this code:

examplevec1<-c(12,19,1)

examplevec2<-rep(10,3)

examplevec1>examplevec2

What would be printed out after you run these three lines (try to answer without actually running the code)?

Show answer

TRUE, TRUE, FALSE

Subsetting, again

RBasics2.2.Subsets & Vector Operations.mp4

Question 2: Consider this code:

examplevec1<-c(12,19,1)

examplevec2<-rep(10,3)

examplevec1[examplevec1>examplevec2]

What would be printed out after you run these three lines (try to answer without actually running the code)?

Show answer

12 19

Graphics

RBasics2.3.Graphics.mp4

Question 3: If you type par(mfrow=c(2,3)) before creating plots, how many plots will be arranged in one window?

Show answer

6

Packages

The end of this video provides the code for the function wilcox.test. The conceptual explanation of this test is in the "Intro to Non-Parametric Tests" module, coming later.

RBasics2.4.Packages.mp4

Popular packages include:

ggplot2 (has some nice graphics options - we will post a tutorial on it as part of this site)

foreign (enables R to open data sets saved from other statistical software packages)

xtable (prints R tables in LaTeX format - LaTeX is a powerful, free editor for writing that includes equations)

and many more.

Question 4: How many times do you need to download a package? How many times do you need to use the library command?

Show answer

Once; Every time you use the package

Directories

This video is not based on the code file that you downloaded in this section.

RBasics2.5.Directories.mp4

Question 5: You try to read in a file and get an error saying that the file can't be found. What's the first thing you check?

Show answer

The working directory, using getwd.

Now you have finished this section. Hurrah!

 During this tutorial you learned:


Operators in review:

<, >, ==, !=, &|

Functions in review:

par(mfrow=c(1,1), las=1), plot(..., main="Title goes here",  xlab="X-axis label goes here",  ylab="Y-axis label goes here",  xlim=c(0,100),  ylim=c(0,100),  pch=1,  cex=5,  col="red"), abline(), colors(), install.packages(), library(), seq(), wilcox.test(..., paired=), getwd(), setwd(), read.csv(), read.table()