Setting Up Your Environment

Before you can start using R, you'll need to install it. Here's how to install R on a Mac using Homebrew

Dataframes

What makes R really powerful is this concept of Dataframes. Dataframes the objects used to represent tables including observations and variables (aka rows and columns). Within a Dataframe, you can store different types of data including dates, integers, floating point numbers and text.

Create a Dataframe object

media <- list("Film" = c("The Matrix", "John Wick", "Babes In Toyland"), "Music" = c("Dogstar"), "Television" = c("The Continental") )

Get Films

Get all films using an index.

media[1]

Get all films using a variable.

media$Film

Get the first object within the ``Film``` column.

 media$Film[1]

Other Objects

The other objects are a bit more standard including: Strings, Floating Numbers, Integers, Boolean Variables, and dates ("2018/08/08").

Custom Functions

You can also write custom functions.

sumMultiply <- function(x, y, z){
  final = (x+y) * z
  return(final)
}

Custom Objects

  • If you want to plot each value of y sequentially, then you'll use single dimension vectors.
  • If you want to create a scatterplot, then you'll use two-dimensional matrices.
  • Regression Models
  • Time series data

Resources