Week 3 Overview
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
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
recall common “vectorized” functions in R such as colMeans, rowMeans, ifelse, etc. (CO 1, 4)
write their own vectorized version of a function in R (CO 1, 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!
display code from previously written functions in R (CO 1, 3)
describe the parts of an R function (CO 1, 4)
describe the difference between a prefix and an infix function (CO 1, 4)
- understand the order of evaluation for user created and built-in infix functions
write an R function that has default arguments, allows for additional arguments, and returns a well-structured named object (CO 1, 3, 4)
- determine appropriate uses for the stop function
- develop a pipeable function that acts on a data frame and one that produces side effects
- create a custom infix function
describe the way that inputs can be specified to a function (CO 1, 3)
- describe positional matching and predict what input values will be assigned to which function values
- explain lazy evaluation and give examples of where it may be important
use if/then/else logic to conditionally execute code
utilize the switch function and compare and contrast its use against if/then/else logic (CO 1, 3, 4)
define environments including temporary environments (CO 1)
- summarize the order in which R attempts to find a requested object
- sketch out the R environment framework and explain the idea of lexical scoping
- discuss the concept of local variables and local environments as compared to global variables and environments
- state the naming conventions for R objects
Reading Data
read delimited data, SAS data files, SPSS files, and other file types into R (CO 2)
- describe the term delimiter
- read comma separated value files into R using the readr package
- explain how the read_ functions determine column types
- describe the readxl package and its functions
- compare and contrast tibbles and data frames
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!