Week 1: Introduction to R
using R as a calculator
R can be used as a calculator:
R code or the
video about simple arithmetic
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, ie, a missing value
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
data types
R has several kinds of data types:
- scalar (can be logical, integer, double, complex, character, raw, and a few others...)
- vector (1 dimensional), matrix (2 dimensional), and array (multidimensional)
- factor (ordered sequence of data; the possible values are called levels)
- data frame (two dimensional data structure, where each column has the same length but different columns can have different types of data)
- list (an ordered collection of objects)
- formulas (used to show how variables are related)
- time series (data collected at several (usually uniform) points in time)
- shingles (typically used in lattice)
- dates and times
- connections (these allow R to communicate outside of the R platform)
missing values
- NA indicates a missing value
- NaN means "not a number"
- Inf and -Inf mean positive and negative infinity, respectively
- NULL is the null object