pow()
function from last timepow()
testpow()
testpow()
testpow()
testConsider the following errors:
Error in x^v: non-numeric argument to binary operator
Error in pow(x = 5, z = 2): unused argument (z = 2)
What do/don’t you like about each error?
Which error message is better? Why?
02:00
pow()
vs. new_pow()
pow()
vs. new_pow()
pow()
vs. new_pow()
Write a function, called diff()
, that takes the difference (subtracts) its first and second arguments. If you have time, try to include any necessary informative error messages.
05:00
A possible solution:
A possible solution with informative error messages:
Testing:
else if
condition to check multiple conditions:What will this print?
00:30
What will this print?
What will this print?
00:30
What will this print?
What will this print?
00:30
What will this print?
R
defaulting na.rm = FALSE
when you take the mean of a variable. You could write a function with a different default!Let’s say you’re tired of R
defaulting na.rm = FALSE
when you take the mean of a variable. You could write a function with a different default!
It might look something like this:
Let’s say you’re tired of R
defaulting na.rm = FALSE
when you take the mean of a variable. You could write a function with a different default!
It might look something like this:
What will
output?
01:00
Write a function that takes two numbers as arguments (inputs) and does the following:
if the input’s sum is positive or 0, take the square root of their sum (recall the sqrt()
) function; otherwise take the absolute value (recall abs()
) of their sum. Throughout the function, print()
some informative messages. Name this function abs_sqrt_sum()
.
05:00