# start out with a number to test
<- 3
x # you'll want your function to return this number
^2
x<- function(...) {
square
...
}# test it out
square(x)
square(53)
53^2 # does this match?
2.4 Functions
Open the slides in a new tab here.
Exercises
- Create a new R script or quarto file and write a function to square a number. You’re tired of writing
x^2
when you want to squarex
, so you want a function to square a number. You can call itsquare()
. I showed this in the slides, now try on your own!