Search⌘ K

Exercise 9: ifelse()

Explore how to use the ifelse function in R to evaluate elements of a numeric vector and determine whether each number is even or odd. This lesson helps you write vectorized conditional logic and display the results with cat(). Understand practical applications of conditional statements in data processing with R.

Problem Statement

Given a vector of numbers, print a vector where each element tells whether the corresponding input vector’s element is an even number or an odd number.

Use cat() for printing.

Input

A testVariable containing the vector of numbers.

Output

A vector where each element corresponds to the correct condition of the elements of the input vector.

Sample Input

testVariable -> c(2, 10, 7, 400)

Sample Output

even even odd even

Test Yourself

Write your code in the given area. If you get stuck, you can look at the solution.

R
# Write your code here
cat(" ")