Welcome to the Hellscape

Module 2: Objects: Vectors, Matrices, and Arrays

R Objects

Classes

Ways to store Objects

Naming Conventions

Vectors

Numbers

Character Strings

Creating Vectors

Missing Values (NA/NaN)

NULL

Vector Name

Coercion

Vector Operations

Arithmetic and Logical Operations

Vector Recycling

Vector Indexing

Create Vectors

Using all() and any()

Vectorized Operation

Filtering

Filtering with subset() and which()

Testing Equality

Matrices and Arrays

Matrices

Create Matrices with dim()

Check Matrix Size

Create Matrices with bind

Index Matrices

Performing Linear Algebra

Matrix sub setting

Use apply()

apply() with user defined function

Arrays

Module 3: Lists, Factors, and Dataframes

Lists

Creating Lists

Attributes of a List

Access Elements in Lists

Add Elements to Lists

Remove Elements from Lists

The lapply() and sapply()

unlist()

Use Lists

Factors and Dataframes

Dataframes

Dataframes vs Lists

Creating Dataframes

General Attributes of Dataframes

Coerce in Dataframes

Access and Subsetting in Dataframes

Adding/Removing

Filtering

NA Values

Names

Factor

Factor Levels

Tables

String Manipulation

Character String

Common Functions

Regular Expression

Escape Sequences

Module 4: Importing, Exporting, Cleaning, and Managing Data

Data Input and Output

Data Management in R

Reading in Data

Writing Data to File

read.table()

Writing to a File

Resources for the More Advanced User

Data Management

Built-In Datasets

Example for data()

Reshaping Data

Removing Missing Data

Module 5: Functions and Control Statements

Functions

Function Syntax

When to Use Functions

Example: Fahrenheit to Celsius

Call a Function

Celsius into Kelvin

Composing Functions: Fahrenheit to Kelven

Composing Functions

Naming Conventions

Variable Scope

References

Testing, Error Handling

Testing

More Tips for Testing

Error Handling

Defining Defaults and Documentation

Define Defaults

Call Function with Defaults

Documentation

Formal Documentation

Control Statements

Types of Control Statements

For Loop

If Else Statement

Small Assignment on Functions with If Else

If Else & For Loop

Small Assignment on the pt.types Dataframe

Module 6: Debugging Functions

R Objects

Debugging

Why we Debug

Debugging R Functions

Principles of Debugging

Debugging Tools in R and Rstudio

Module 7: Materials

Performance Enhancement

Background

Writing Fast R Code

Vectorization

A Simple Example

Example with User Defined Function

Time Consumption

More Vectorized Functions

Simulation Speedup

Time Consumption

Growing Objects

A Few more Examples

Key Takeaways

Vectorization Demo Code

Parallel

Background

Parallel in R

When to Parallel

Simple Example

Functions with Built-In Multiple Core Support

Use mclapply()

Windows parLapply()

Parallel Demo Code