2.3 Functions

Open the slides in a new tab here.

Exercises

  1. Square a number. You’re tired of writing x^2 when you want to square x, so you want a function to square a number. You can call it square(). I showed this in the slides, now try on your own!
# start out with a number to test
x <- 3
# you'll want your function to return this number
x^2
square <- function() {
  
}
# test it out
square(x)
square(53)
53^2 # does this match?

Resources