Question 1.

Jacks.Equation <- function(smeters = 0, trees = 0, drunkenness = 7) {
  output <- (smeters * trees) - drunkenness * 324 + log(smeters)
  
  return(output)
}
paste("The amount of gold is", Jacks.Equation(1000, 30, 7),".")
## [1] "The amount of gold is 27738.907755279 ."

Question 2.

data1 <- c(6, 3, 8, 6, 3, 2, 3, 2, 100)
standardize.me <- function(x) {
  output <- (x - mean(x))/ sd(x)
  
  return(output)
  
}

standardize.me(data1)
## [1] -0.2740789 -0.3677514 -0.2116305 -0.2740789 -0.3677514 -0.3989756
## [7] -0.3677514 -0.3989756  2.6609937

Question 3.

how.many <- function(data, value) {
  log.in <- data %in% value
  output <- length(data[log.in])
  
  return(output)
}
data2 <- c(1,1,9,3,2,1,1)
how.many(data2, 1)
## [1] 4
how.many(data2, -100)
## [1] 0

Question 4.

recode.numeric <- function(x, lb, ub) {
  log.1 <- x > ub | x < lb
  x[log.1] <- NA

  return(x)
  
}
survey <- data.frame(
                     id = 1:6,
                     q1 = c(6, 2, 5, -1, 11, 100),
                     q2 = c(-5, 4, 65, 3, 7, 6),
                     q3 = c(2, 1, 2, 45, 5, -5)
                     )

recode.numeric(survey, 1, 10)
##   id q1 q2 q3
## 1  1  6 NA  2
## 2  2  2  4  1
## 3  3  5 NA  2
## 4  4 NA  3 NA
## 5  5 NA  7  5
## 6  6 NA  6 NA

Q5

recode.factor <- function(x, old, new) {
  log.2 <- x %in% old
  x[log.2] <- new
  return(x)
}

Not finished!!