Use the code below to re-define the standardize() function and to create a vector with standardized numbers.

standardize <- function (x) {
  (x - mean(x, na.rm = TRUE)) / sd(x, na.rm = TRUE)
}

standardized_vector <-
  standardize(sample(1:100, 30))

1

Using a for()-loop, loop through each element of the vector, add the number pi, and print the result.
There’s a pre-defined value in R for pi. Just type pi and you’ll receive 3.141593. You need to wrap what the function does within the print() function.

2

Repeat the previous exercise, but this time the results should be printed all at once in a vector. Use the sapply() function here.
You don’t need the print() function anymore.

3

Now, we want to have the same output as a list.
You can either use lapply() or map() from the purrr package.