--2-When and how you should write a function
#To help you test your code, create a vector x containing the numbers 1 through 10.
#Rewrite the code snippet to use the temporary variable x instead
#of referring to the data frame column df$a
# Define example vector x
x<-c(1:10)
# Rewrite this snippet to refer to x
(x - min(x, na.rm = TRUE)) /
(max(x, na.rm = TRUE) - min(x, na.rm = TRUE))# Define the intermediate variable rng to contain the range of x
#using the function range().
# Specify the na.rm() argument to automatically ignore any NAs in the vector.
# Rewrite the snippet to refer to this intermediate variable.
# Define example vector x
x <- 1:10
# Define rng
rng<-range(x,na.rm=TRUE)
# Rewrite this snippet to refer to the elements of rng
(x - min(x, rng)) /
(max(x, rng) - min(rng))Last updated