Question: Create an R function pwfun ( ) , which computes values of the piece - wise ( mathematical ) function pwfun defined in the following
Create an R function pwfun which computes values of the piecewise mathematical function pwfun
defined in the following way:
pwfun
Its graph is as follows.
Your R function pwfun should also accept x as a vector of arbitrary length and return vector of the same length with entries defined as values of the mathematical function pwfun
evaluated at the corresponding entries of vector x
Here are some input vectors and what you should get as a corresponding output.
pwfun
pwfunc
x c
pwfunx
Hint:
Obviously, one way to solve this is using ifelseifelse statment. Apart from that, you can also take a look at the R function ifelse which you could call twice.
Be careful: because R has assignment operator code lines a and a do NOT have the same meaning!
While a checks whether variable a is less than
a means the same as a which is assigning the value to the variable a
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
