Page 1 of 1

Q2. Below is an R function that takes a numeric vector as an argument and returns the difference between the largest and

Posted: Sat May 14, 2022 4:46 pm
by answerhappygod
Q2. Below is an R function that takes a numeric vector as an
argument and returns the difference between the largest and
smallest item in the vector x.
DiffMaxMin <- function(x){
return(max(x)-min(x))
}
• Now use map functionality and the above DiffMaxMin function to
get the difference between the largest and smallest item in each
column of a numeric data frame df given below. Note that the
purpose of map functions is to avoid using loops.
df <- data.frame(
a = rnorm(10),
b = rnorm(10),
c = rnorm(10),
d = rnorm(10) )
• Perform the above task by using for-loop and without using map
or lapply functionalities.