Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started