Question: 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

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

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!