Are these functions vectorized?
Exercise Type: Prediction
Instructions
Take a look at the function definitions below. All these functions have a primary argument x
which is assumed to be a single value. Assess whether they can be run with immediate vectorization, and answer these questions:
- Can the function be run with multiple values supplied as
x
? - If not, why?
A
DegToRad <- function(x) x/180*pi
B
NumberPositive <- function(x) if(x > 0) message("x is positive!")
C
CelsiusToFahrenheit <- x * 1.8 + 32
D
RandomLetter <- function(x) sample(letters, x, replace=TRUE)
E
JustSaying <- function(x) paste("I say:", x)