How to do it…

Let’s say the name of the function is fDescriptive. The prefix f in the name of the function is just for convenience so that you can easily identify that this object is a function. The name of the first argument could be any valid object name. In this recipe, the numeric input argument is defined by numVec, and the second argument is defined as type. Now, the function can be written as follows:

    fDescriptive <- function(numVec, type = "classical"){
avg <- mean(numVec)
std <- sd(numVec)
med <- median(numVec)
medad <- mad(numVec)
out1 <- c(mean = avg, sd = std)
out2 <-c(median = med, mad = medad)
if(type== "classical")
return(out1)
else if (type == "robust")
return(out2)
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset