Skip to Content
Modern R Programming Cookbook
book

Modern R Programming Cookbook

by Jaynal Abedin
October 2017
Beginner to intermediate
236 pages
7h 38m
English
Packt Publishing
Content preview from Modern R Programming Cookbook

How to do it…

To check the input data types, the required function is is.x, where x is a placeholder for character, numeric, logical, vector, matrix, and so on. Using this function, the data type and data structure can be easily assessed. You will use the is.x type of function in the body of the fDescriptive function as follows:

    fDescriptive <- function(numVec, type = "classical"){      type <- tolower(type)      if(is.numeric(numVec) & is.vector(numVec)){        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)      }    }
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R Cookbook, 2nd Edition

R Cookbook, 2nd Edition

JD Long, Paul Teetor

Publisher Resources

ISBN: 9781787129054Supplemental Content