Recap

In the last session we saw the RStudio interface and started typing at the R command prompt to practice basic R calculations and variable setting. Then we saw how to read files into R.

More on Files

As a review: Here is how we were reading our data files last time:

A note on Paths

To use data stored on a computer we need to tell R where it is. This is done using paths.

Paths can be absolute:

Your paths will be different

Folders/Directories are separate by / with the file name at the end.

Paths can also be relative:

“From where I am open the mtcars file”

Your are Here

How do you figure out what the path should be?

## [1] "C:/Users/rharbert/Documents/GitHub/bioinformatics/docs"

Prints the current path of your R session.

If you need to change the directory you are working in, use:

Basic plotting

One of R’s biggest advantages is the ability to create high quality graphics in nearly any format or style. Today we will be working with the basic plotting features of R. These are good, but limited at times. Later we will take a look at the ggplot library. ggplot is the current ‘state of the art’ in graphics for R.

OK. That was not so great. Let’s try somethnig more useful for visualizing these data. We can tell plot() which columns we want to create a scatterplot for:

##  [1] "X"     "model" "mpg"   "cyl"   "disp"  "hp"    "drat"  "wt"   
##  [9] "qsec"  "vs"    "am"    "gear"  "carb"

OR we can create other types of plots by calling other functions. e.g., a histogram of boxplot:

Repeating Actions

Programming is just getting your computer to do the same thing a bunch of times so you don’t have to.

The fundamental structure in any programming language to make this happen is the Loop. We will look at loops to understand the process.

Loops

Repeating tasks using loops

## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
## [1] 10

Catch loop output in a vector or list

apply family functions

The Apply functions in R provide efficient repetition that usually out-performs for loops.

##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    1    1    1    1
## [2,]    2    2    2    2    2
## [3,]    3    3    3    3    3
## [4,]    4    4    4    4    4
## [5,]    5    5    5    5    5

Homework Assignment

  1. Read your data into R. Create a simple plot of some of your data. Post it to the #plots channel.
  2. DISCUSSION: In the slack #discussion channel we will host this week’s discussion. Please search online for an R related resource for R beginners. This could be a book/eBook, a web tutorial, youtube video, or something else. Post what you find. Look through the resource you found and tell the group about it (what it is, how it is structured, who it is targetted to).