Introduction to R Programming

Analyzing data in rstudio.pdf

Image by Brooke Carneal, a PSYC300 student, Summer 2021

05-A: R Markdown and Knitting Files

For assignments, we will be using R Markdown. This will allow us to have all our text notes, code, and output all in one neatly formatted document. It may seem magical, but it's simple to use.

Video (11:46)

05-B: Vectors and Classes of Vectors

DOWNLOAD: For this video we will use the R Vectors Rmd file located here.

Vectors

Video (7:29)

Classes of Vectors

Video (12:49)

05 - C: Functions, Packages & Libraries, Reading in Data & Looking at Data

DOWNLOAD: For this video we will use the R Functions Rmd file located here.

Functions

Video (8:57)

Packages & Libraries

Video (6:59)

Reading-in Data

Video (5:15)

Looking at Datasets

Video (6:45)

More Looking at Datasets

Video (8:52)

05-D: Subsetting and Indexing

DOWNLOAD: For this video we will use the R Subsetting Rmd file located here.

First, a matrix is an arrangement of individual cells organized into rows and columns. You are most likely used to seeing numbers in these cells, as you would in an Excel file or dataset.

First, let's be sure we can identify the rows and columns of a matrix.

Rows run horizontally, as indicated in the image below.

Columns, however, run vertically, as seen below.

Introduction to Indexing

When we want to index into a matrix, we want to identify individual cells, based on their row and column location. When stating the index of a cell, we first state the row then the column. Let's take a look at the simple example matrix above with 5 rows and 4 columns and see if we can identify the index of different cells. For simplicity, we are not going to give these rows and columns any specific meaning. We just want to find the numbers in the matrix.

Let's say we wanted to specify the cell in the first row and first column. The index of that cell is (1,1). What is the value in that cell? It would be 1.

OK, so now what about the second row, first column? Remember, the index lists the row first then the column. That answer would be (2,1) and the value is 4.

Practice indexing individual cells in the matrix and then watch how we can do this in R!

Video (13:48)

Subsetting

Video (14:51)

Subsetting and Conditional Indexing

Video (31:00)

05-E: New Datasets, Subsetting Review & Data Cleaning & Missing Values

DOWNLOAD: For this video we will use the R Dataset Cleaning Rmd file located here.

How to Approach a New Dataset

Video (13:27)

Review of Subsetting

Video (9:09)

Data Cleaning & Missing Values

Video (14:57)

05-F Common Issues when Learning R

References