Solution Review: Returning from a Function
In this review, we give a detailed analysis of the solution to this problem.
Solution: Returning from a Function
Press + to interact
R
evenOdd <- function(testVariable){output <- vector("character", 0) # initializing an empty character vectorfor(v in testVariable){if(v %% 2 == 0){# Insert even in vector if conditional statement satisfiedoutput <- c(output, "even")}else{# Insert odd in vector if conditional statement not satisfiedoutput <- c(output, "odd")}}return(output) # returning the output vector.# You can also simply write output here.}# Driver CodeevenOdd(c(78, 100, 2))
Explanation
The input to the ...