mycalc <- function(x, y, fun) 
x <- 1:5
y <- c(5, 2, 3, 10, 2)  
mycalc<- mycalc(x, y, fun) {
  if(fun == "sum") {
    o <- sum(x, y)
  } else if(fun == "subtract") {
    o <- (x-y)
  } else if(fun == "multiply") {
    o <- (x*y)
  } else if(fun == "divide") {
    o <- (x/y)
  } else {
    o <- paste("Not a recognized function")
  }
  return(o)
}


BigBoat8542/Geog_analysis_R documentation built on Dec. 17, 2021, 10:50 a.m.