Solution Review: Creating Functions
In this review, we provide a detailed analysis of the given problem.
We'll cover the following
Solution: Creating a Function
evenOdd <- function(testVariable){if(testVariable %% 2 == 0){cat("even")} else{cat("odd")}}# Driver CodeevenOdd(78)cat("\n")evenOdd(67)cat("\n")evenOdd(1)
Explanation
Create a function using the following syntax:
evenOdd <- function(testVariable)
{
<Conditional Block>
}
The function takes an argument testVariable
and accordingly performs some tasks on it.