Question 1
Summary = function(x){
if (mode(x)=='numeric'){
Sd = sd(x)
Summary = summary(x)
S = c(Summary, " Standard Deviation"= sd)
return (S)
}else {
return(table(x))
}
}
x = c(12, 20, 18, 32, 15, 20)
y = c("M", "M", "F", "F", "M", "M", "M", "F")
Summary(x)
## $Min.
## [1] 12
##
## $`1st Qu.`
## [1] 15.75
##
## $Median
## [1] 19
##
## $Mean
## [1] 19.5
##
## $`3rd Qu.`
## [1] 20
##
## $Max.
## [1] 32
##
## $` Standard Deviation`
## function (x, na.rm = FALSE)
## sqrt(var(if (is.vector(x) || is.factor(x)) x else as.double(x),
## na.rm = na.rm))
## <bytecode: 0x0000000013fb9fd8>
## <environment: namespace:stats>
Question 2
Capital = function(x){
one = toupper(substr(x,1,1))
two = tolower(substr(x,2,100))
paste0(one, two)
}
Capital(names(mtcars))
## [1] "Mpg" "Cyl" "Disp" "Hp" "Drat" "Wt" "Qsec" "Vs" "Am" "Gear"
## [11] "Carb"