Question: Please help me to write R code to perform the following tasks. Write and test the function even_odd() that accepts a vector of integers as

Please help me to write R code to perform the following tasks.

Write and test the function even_odd() that accepts a vector of integers as input and returns a two-element vector containing the number of evens and the number of odds. The function would be used as follows:

even_odd(9:1) # returns 4 5 (4 evens, 5 odds)

even_odd(c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) # returns 4 5 (4 evens, 5 odds)

Zero is not considered an even number. Use the ifelse() and sum() functions inside the body of the even_odd function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!