Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help by coding all parts for problems in R through RMarkdown The objective of this question is to introduce the ifelse() function and give
please help by coding all parts for problems in R through RMarkdown
The objective of this question is to introduce the ifelse() function and give practice with vectorization. (a) Write a function called my _ifelse() that implements a vector form of the if-else statement without the ifelse() function. That is, the ith element of my ifelse (test, yes, no) will be yes [i] if test [i] is TRUE and no [i] if test [i] is FALSE. Values of yes or no should be recycled if either is shorter than test. Hint: This can be written as a loop, but a vectorized solution is better. (b) Verify that your my_ifelse() function works by executing the following commands: x < (1:10) pi my_ifelse(x %% 1 >= 0.5, x %/% 1 + 1, x %/% 1) (c) Use your my_ifelse() function to write my _abs() and my_sign() functions that, respectively, compute the absolute values and signs of the elements of a numeric vector. The respective outputs of my_abs (x) and my_sign() should be identical to abs(x) and sign(x) for any numeric vector x. Hint: It may be helpful to use my_abs () when writing my_sign().
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