raise <- function() {
}
# test with
raise(x = 2, power = 4)
# should give you
2^42.5 Functions
Open the slides in a new tab here.
Exercises
- Write a function to raise to any power. You don’t just want to square numbers, you want to raise them to higher powers too. Make a function that uses two arguments,
xfor a number, andpowerfor the power. Call itraise().
- Change your
raise()function to default to squaringxwhen the user doesn’t enter a value forpower.
# test
raise(x = 5)
# should give you
5^2