6. Defining functions. You are given a vector of stock returns, which is stored as the variable returns
. You want to
write a function in R
to standardize the returns.
Recall that a variable can be standardized by subtracting its mean and then dividing by its standard deviation. This can be done with the functions mean()
and sd()
.
Functions in R
have the following form: function_name <- function(arg_1, arg_2, ...){classFunction body}
. The last expression to be evaluated in a function is its return value.