Week 1: Introduction to R



connecting to the llc.stat.purdue.edu computer server

Instructions for connecting to the server for class and for our research projects.
If you prefer to see videos, they are given at the top of the instruction page.
If you prefer written instructions, those are listed too.
There are instructions for both the Mac and Windows computers.


adjusting the screen size

How to adjust the screen size? video instructions to adjust screen size. Also there are instructions for how to change the time and weather to the Lafayette, Indiana, area.


load R or Rstudio

How to load R or Rstudio? video instructions to load R or Rstudio.


introduction to the R platform

Starting point for many R resources: The R Project for Statistical Computing

Some helpful resources; you will find which ones suit you best (we are all open to feedback on these resources; please make suggestions if you want to add some here):
examples of plots

R has powerful graphical capabilities, which are easy to use: video of some example plots.
This video also shows how to install packages in R. When it becomes necessary, it will be helpful to see all Contributed Packages from CRAN.
To install packages (for example, here, the mapproj and then the maps package), type:
install.packages("mapproj")
install.packages("maps")
and then the R software will ask which mirror you want. Afterwards, the package will be installed.
Installations of packages only need to be done one time.
It is necessary, however, to load a package at the start of every session where you want to use it, for instance:
library(maps)

using R as a calculator

R can be used as a calculator: R code or the video about simple arithmetic


opening files we worked on earlier, in Rstudio

To find and open a file we worked on earlier in Rstudio, here are video instructions for opening files in Rstudio


the structure of the llc computer server

Where should I store my files and folders? How are things structured on llc?
Here is a picture of the llc structure, and two videos that explain this structure:
video about the picture of the structure
and
video that demonstrates moving around the llc computer's directories.
If you want to save files into your group directory from within Rstudio itself,
here is a third resource, namely, a video about using Rstudio to save files in the right place
Here are the two sample files used in the video above: samplefile.R and samplefile2.R


introduction to vectors and recycling

We introduce vectors and recycling: R code or the video introduction to vectors and recycling


example with generating uniform random numbers; and an example why "for loops" are slow in R

We experiment with uniform random numbers and for loops: R code or the video about uniform random numbers and for loops


example with rolling dice

We experiment with rolling 100 dice at random, and using vectorized operations to study the results: R code or the video about rolling dice


example with normally distributed values

We experiment with generating some normally distributed random values,
and again we use vectorized operations to study the results: R code or the video about vectors of normally distributed values


more examples for discrete values

We mention a few more functions for discrete values: R code or the video about more functions for discrete values


dealing with NA's

We discuss how to deal with NA values in a vector: R code or the video about NA values and how to handle them


case study: seq function

A case study, looking carefully at the seq function: R code or the video about the seq function


case study: rep function

A case study, looking carefully at the rep function: R code or the video about the rep function


4 ways to index vectors

A comprehensive look at how to index vectors: R code or the video about indexing vectors


introduction to built-in data sets in R

R has some built-in data sets. We take a brief look at the co2 data, including some ways to use different ways to index this data:
R code or the video about built-in data and indexing carbon dioxide data


introduction to functions

It is straightforward to write a function: R code or the video about writing a function


introduction to data frames
We define factors, levels, and data frames, using the CO2 (Carbon Dioxide Uptake in Grass Plants) built-in R example:
R code or the video about these definitions


data types

R has several kinds of data types:
missing values