Lab 4 Activity Activity4 Lab4 Instructions
User Manual:
Open the PDF directly: View PDF
.
Page Count: 1

Lab 4 - Activity
Oleksandr Savenkov
10/3/2018
1. Write a function that normalizes a vector (with two parameters) :
•vector to be normalized
•
parameter that allows normalize the vector in two ways: only centered with zero mean and also
standardize with mean zero and standard deviation 1
Example:
•input (1, 2, 3, 4)
•centered vector is
standardize(a, centered_only = TRUE)
## [1] -1.5 -0.5 0.5 1.5
•standardized is
standardize(a, centered_only = FALSE)
## [1] -1.1618950 -0.3872983 0.3872983 1.1618950
2. Modify previous function in order to handle missing values in a vector
standardize(c(1,2,3,4,NA))
## [1] NA NA NA NA NA
standardize(c(1,2,3,4,NA), na.rm = TRUE)
## [1] -1.1618950 -0.3872983 0.3872983 1.1618950 NA
2. Create a 4 by 4 matrix
## [,1] [,2] [,3] [,4]
## [1,] 1 5 9 13
## [2,] 2 6 10 14
## [3,] 3 7 11 15
## [4,] 4 8 12 16
Create a function to calculate sum of matrix elements without built-in function sum()
1