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
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
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
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.
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.
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:
How R deals with logical operators
How R compare objects such as numbers & vectors with logical operators
About subsetting with conditioning
Functions and arguments to improve graphics including placing multiple graphs next to (or above) each other and changing the orientation of the y-axis labels
How to change the dimensions of your graph by dragging the frame
How to add lines to your graphic (horizontal, vertical, & with a slope)
The arguments to change the main title, x-axis label, y-axis label, axis limits, and the type, size, & color of the points
About packages in R and how to install a package
How to makes a sequence of numbers
An introduction to the function runs the rank sum test
How to read in a dataset and change your working directory [note, for those familiar with UNIX commands, you can start your file path with ~ to reference your home directory]
About workspaces in R
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()