Unit 2: Working with Data

In this unit you will learn more about matrices, dataframes,and lists, and how to import, export, and manage data.

Data for the labs for this unit can be found here

Lesson 1. How to work with dataframes and matrices

Lecture: Details of dataframes and matrices.

Learning Goals:

• Make and manipulate matrices,
• Make and manipulate dataframes,
• Examine the structure and contents, and extract elements of dataframes.

SWIRL:

Lab: Unit 2: Lab 1

Functions: `matrix()`, `data.frame()`, `rbind()`, `cbind()`, `head()`,`tail()`, `str()`, `is.foo()`, `nrow()`, `ncol()`, `dim()`, `rowSums()`, `colSums()`, `t()`.

Lesson 2. How to extract subsets of data

Lecture: Subsetting and indexing in R

Learning Goals:

• Extract dataframe columns with column names (`\$`, `[, 'name']`),
• Subset vectors with `[i]`,
• Subset matrices, arrays, and dataframes with `[i, j]`,
• Subset with logical operators (`>`, `<`, `!=`, `==`).

SWIRL: Indexing and subsetting

Lab: Unit 2: Lab 2

Reading: Healy, K. 2018. The Plain Personâ€™s Guide to Plain Text Social Science Link. Chapter 1. Introduction. (more if you want!)

Functions: `order()`, `subset()`, `[`, `[[`, `\$`

Lesson 3. How to get data into and out of R

Lectures:

Learning Goals:

• Clean spreadsheets and text files,
• Read in .txt and .csv files,
• Write data to files.

SWIRL: Importing data

Lab: Unit 2: Lab 3

Best Practice: Managing Data

Functions: `read.table()`, `read.csv()`, `write.table()`

Lesson 4. How to work with and access lists

Learning Goals:

• Create lists using `list()`,
• Index and subset simple lists,
• Access model output and other lists.

SWIRL: Lists

Lab: Unit 2: Recap

Functions: `list()`