Class Activity

Instructions: Work with a neighbor to answer the following questions, then we will discuss the activity as a class. To get started, download the class activity template file.

What will happen?

For each question, predict what will happen when the code is run. Then run the code and check whether your prediction was correct.

x <- 10

g02 <- function(x){
  x <- x + 1
  return(x)
}

g02(x)
x + 1
x <- 10

g02 <- function(x){
  x <- x + 1
  return(x)
}

x <- g02(x)
x + 1
g02 <- function(y){
  y <- y - 1
  return(y)
}

g02(g02(20))

Practice with anonymous functions

  1. Use the integrate() and an anonymous function to find the area under the curve for the following functions: