Write a function with the name standardize
that normalizes the values of a given vector with the following formula:
\[(x - \bar{x}) / S\]
where \(x\) is each input value, \(\bar{x}\) is the sample mean value and \(S\) the sample standard deviation.base R
function for computing the standard deviation function is sd()
. Don’t forget to use the option na.rm = TRUE
and be careful when setting the brackets around the formula.
As a preparation for the next task, please run the following code create a vector with 30 randomly selected values.
vector <- sample(1:100, 30)
standardize()
function to see if it works.
<
) to check if a condition is true or false. For printing, you should use the print()
function.