Vectorized functions

Learning Objectives

This week, students will:

  • Learn to run functions on multiple datasets by using:
    • vectorized functions
    • apply functions
    • the function rowwise() from dplyr
  • Understand that the group_by() function from dplyr runs the same function on multiple data sets
  • Learn the difference between these four methods for code reusing
  • Manipulate character strings with the package stringr and paste()

Practice Objectives

  • Creating functions
  • Deafult values for arguments
  • Reading tables
  • Using functions from dplyr and ggplot2

Setup your RStudio project (5 min)

Vectorized functions (5 min)

Exercise 1: Calculating the mass of a bunch of dinosaurs (35 min)

sapply() (5 min)

Exercise 2: Conditioning on length (15 min)

mapply() (5 min)

Exercise 3: A data set of dinosaur lengths (30 min)

Discussion (20 min)