Exercises

Let's revisit the function we defined in the last exercise:

p <- 5
do.something <- function(n, d) {
  m <- n + p
  m/d
}

(1) Is the function "vectorized"? i.e. if the input(s) is a vector are the outputs also vectors? Show by example. This question is not trivial, because vectorized functions can be used directly for column transformations (after all, columns in a data.frame are just vectors).

(2) Based on what we learned about vectorized functions, is the ifelse function vectorized? what about if and else? Once again answer the question using examples for each.

results matching ""

    No results matching ""