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))
for()
-loop, loop through each element of the vector, add the number pi
, and print the result.
pi
. Just type pi
and you’ll receive 3.141593. You need to wrap what the function does within the print()
function.
sapply()
function here.
print()
function anymore.
lapply()
or map()
from the purrr
package.