October 2017
Beginner to intermediate
236 pages
7h 38m
English
Let's take a look at the following steps to perform the given task of calculating the mean, standard deviation, median, and MAD based on a value of another variable sym:
option1 <- function(x, sym){ switch(sym, classical = c(mean= mean(x, na.rm = T), std = sd(x, na.rm = T)), robust = c(med = median(x, na.rm = T), mad = mad(x, na.rm = T)) ) }
option2 <- function(x, sym){ if(sym=="classical"){ out <- c(mean = mean(x,na.rm = T), std= sd(x,na.rm = T)) return(out) } else if(sym=="robust"){ out <- c(med = median(x, na.rm = T), mad = mad(x, na.rm = T)) return(out) } else ...