Week 3 Overview

Published

2026-08-11

This wraps up the content for week 2. Now we require some practice! You should head back to our Moodle site to check out your homework assignment for this week.

This third week we tackle improved repeated computation through vectorized functions, how to write our own functions, and reading in data through the tidyverse. The tidyverse is a widely used suite of packages that all work together and allow you to read in data and do most common data manipulations.

Week 3 (Optional) Additional Readings/Learning Materials

Loops and Vectorized Functions

Writing Functions

Reading Data

Week 3 Learning Objectives

Upon completion of this week, students will be able to:

Vectorized Functions

  1.    program using the “apply family” of functions in R (CO 1, 3, 4)

    a.    differentiate between the apply family of functions in R including, but not limited to, mapply, sapply, lapply, apply, and replicate b.    manipulate R code that uses loops to instead use the proper apply function c.    utilize anonymous functions in calls to the apply family of functions in R

  2.    recall common “vectorized” functions in R such as colMeans, rowMeans, ifelse, etc. (CO 1, 4)

  3.    write their own vectorized version of a function in R (CO 1, 4)

  4.    describe what an anonymous function is and how it differs from other functions (CO 1, 4)

Writing Functions

Note: Not all of these are covered in this week’s function writing videos - we’ll revisit the topic later!

  1. display code from previously written functions in R (CO 1, 3)

  2. describe the parts of an R function (CO 1, 4)

  3. describe the difference between a prefix and an infix function (CO 1, 4)

    1. understand the order of evaluation for user created and built-in infix functions
  4. write an R function that has default arguments, allows for additional arguments, and returns a well-structured named object (CO 1, 3, 4)

    1. determine appropriate uses for the stop function
    2. develop a pipeable function that acts on a data frame and one that produces side effects
    3. create a custom infix function
  5. describe the way that inputs can be specified to a function (CO 1, 3)

    1. describe positional matching and predict what input values will be assigned to which function values
    2. explain lazy evaluation and give examples of where it may be important
  6. use if/then/else logic to conditionally execute code

  7. utilize the switch function and compare and contrast its use against if/then/else logic (CO 1, 3, 4)

  8. define environments including temporary environments (CO 1)

    1. summarize the order in which R attempts to find a requested object
    2. sketch out the R environment framework and explain the idea of lexical scoping
    3. discuss the concept of local variables and local environments as compared to global variables and environments
    4. state the naming conventions for R objects

Reading Data

  1. read delimited data, SAS data files, SPSS files, and other file types into R (CO 2)

    1. describe the term delimiter
    2. read comma separated value files into R using the readr package
    3. explain how the read_ functions determine column types
    4. describe the readxl package and its functions
    5. compare and contrast tibbles and data frames
  2. write a stored data set to a file using different delimiters (CO 2)

Use the table of contents on the left or the arrows at the bottom of this page to navigate to the next learning material!